home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / phigs / ptk.lha / ptk / source / library / plib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-01  |  101.0 KB  |  3,474 lines

  1. /*----------------------------------------------------------------------------
  2.  
  3.   Module name: phigslib.
  4.  
  5.   Author: Toby Howard.
  6.  
  7.   Function: This module contains a collection of
  8.             useful routines, built on top of KRT3.
  9.             See document KRT3/57 for detailed specs.
  10.  
  11.   Dependencies: machine.h.
  12.  
  13.   Internal function list: ptk_setstringprompt, inelemlist, testpoint,  
  14.   ptk_redistributepriorities, ptk_findpriority, traversestruct, box
  15.  
  16.   External function list: ptk_readint, ptk_readfloat, 
  17.   ptk_readstring, ptk_stackstruct, ptk_unstackstruct,
  18.   ptk_openstruct, ptk_closestruct, 
  19.   ptk_getpickid, ptk_elemcount, ptk_structexists, 
  20.   ptk_getelemtype, ptk_getelemtypename, ptk_copyelem, 
  21.   ptk_getprimname, ptk_removestruct, ptk_findelemtype, 
  22.   ptk_countchildren, ptk_structsummary, 
  23.   ptk_setattrasf, ptk_setallattrasf, ptk_setedgebundlerec,
  24.   ptk_setinteriorbundlerec, ptk_setpolylinebundlerec,
  25.   ptk_setpolymarkerbundlerec, ptk_settextbundlerec,
  26.   ptk_setstandardviewport, ptk_poststruct, ptk_postrelative, 
  27.   ptk_changepostpriority,
  28.   ptk_drawcolourtable, ptk_inqmaxdevicecoords, ptk_inqmaxdevicecoords3, 
  29.   ptk_arrow, ptk_grid
  30.  
  31.   Hashtables used: "structureid".
  32.  
  33.   Modification history: (Version), (Date), (name), (Description).
  34.  
  35.   1.0, ?????, T. Howard, First version.
  36.  
  37.   1.1, 15th July 1988, S. Larkin, Modified to work with VAX PHIGS.
  38.  
  39.   1.2, 24th August 1988, S. Larkin, Procedure ptk_drawcolourtable added.
  40.  
  41.   2.0, 8th January 1991, G. Williams, Converted from Pascal to C. removed
  42.   obsolete functions.
  43.  
  44.   2.1, 15th February 1991, G. Williams, Function ptk_findelemtype added.
  45.  
  46.   2.2, 2nd May 1991, G. Williams, Bundled attribute functions added:
  47.   ptk_setattrasf, ptk_setallattrasf, ptk_setedgebundlerec,
  48.   ptk_setinteriorbundlerec, ptk_setpolylinebundlerec,
  49.   ptk_setpolymarkerbundlerec, ptk_settextbundlerec.
  50.  
  51.   3.0, June 1992, G. Williams, Converted to ISO PHIGS C.
  52.  
  53.   3.1, July 1992, G. Williams, Extended to support PHIGS PLUS.
  54.  
  55. ----------------------------------------------------------------------------*/
  56.  
  57. #include <stdio.h>
  58. #include <math.h>
  59. #include <phigs.h>
  60. #include "ptk.h"
  61.  
  62. typedef struct ptksstructstack 
  63. {
  64.   Pint structid;
  65.   Pint elemptr;
  66.   struct ptksstructstack *next;
  67. } ptksstructstack;
  68.  
  69. typedef struct ptkseditmodestack 
  70. {
  71.   Pedit_mode editmode;
  72.   struct ptkseditmodestack *next;
  73. } ptkseditmodestack;
  74.  
  75. static ptksstructstack *structstack = NULL;
  76. static ptkseditmodestack *editmodestack = NULL;
  77.  
  78. /* Possibly Implementation dependent, if version has
  79. ** PHIGS extension elements e.g. DEC
  80. */
  81. #ifdef SUN
  82. #define NUMPHIGSELEMS 103
  83. #else
  84. #define NUMPHIGSELEMS 71
  85. #endif
  86.  
  87. /* PHIGS PLUS bits */
  88. static char *elemlist[] = 
  89. {
  90. "all",
  91. "nil",
  92. "polyline3",
  93. "polyline",
  94. "polymarker3",
  95. "polymarker",
  96. "text3",
  97. "text",
  98. "annotation_text_relative3",
  99. "annotation_text_relative",
  100. "fill_area3",
  101. "fill_area",
  102. "fill_area_set3",
  103. "fill_area_set",
  104. "cell_array3",
  105. "cell_array",
  106. "generalized_drawing_primitive3",
  107. "generalized_drawing_primitive",
  108. "set_polyline_index",
  109. "set_polymarker_index",
  110. "set_text_index",
  111. "set_interior_index",
  112. "set_edge_index",
  113. "set_linetype",
  114. "set_linewidth_scale_factor",
  115. "set_polyline_colour_index",
  116. "set_marker_type",
  117. "set_marker_size_scale_factor",
  118. "set_polymarker_colour_index",
  119. "set_text_font",
  120. "set_text_precision",
  121. "set_character_expansion_factor",
  122. "set_character_spacing",
  123. "set_text_colour_index",
  124. "set_character_height",
  125. "set_character_up_vector",
  126. "set_text_path",
  127. "set_text_alignment",
  128. "set_annotation_text_character_height",
  129. "set_annotation_text_character_up_vector",
  130. "set_annotation_text_path",
  131. "set_annotation_text_alignment",
  132. "set_annotation_style",
  133. "set_interior_style",
  134. "set_interior_style_index",
  135. "set_interior_colour_index",
  136. "set_edge_flag",
  137. "set_edgetype",
  138. "set_edgewidth_scale_factor",
  139. "set_edge_colour_index",
  140. "set_pattern_size",
  141. "set_pattern_reference_point_and_vectors",
  142. "set_pattern_reference_point",
  143. "add_names_to_set",
  144. "remove_names_from_set",
  145. "set_individual_asf",
  146. "set_hlhsr_identifier",
  147. "set_local_transformation3",
  148. "set_local_transformation",
  149. "set_global_transformation3",
  150. "set_global_transformation",
  151. "set_modelling_clipping_volume3",
  152. "set_modelling_clipping_volume",
  153. "set_modelling_clipping_indicator",
  154. "restore_modelling_clipping_volume",
  155. "set_view_index",
  156. "execute_structure",
  157. "label",
  158. "application_data",
  159. "generalized_structure_element",
  160. "set_pick_identifier",
  161. #ifdef SUN
  162. "polyline_set3_with_data",
  163. "fill_area_set3_with_data",
  164. "triangle_strip3_with_data",
  165. "quadrilateral_mesh3_with_data",
  166. "set_of_fill_area_set3_with_data",
  167. "non-uniform_b-spline_curve",
  168. "non-uniform_b-spline_surface",
  169. "cell_array3_plus",
  170. "set_text_colour",
  171. "set_polymarker_colour",
  172. "set_edge_colour",
  173. "set_polyline_colour",
  174. "set_curve_approximation_criteria",
  175. "set_polyline_shading_method",
  176. "set_interior_colour",
  177. "set_back_interior_colour",
  178. "set_back_interior_style",
  179. "set_back_interior_style_index",
  180. "set_reflectance_properties",
  181. "set_back_reflectance_properties",
  182. "set_interior_shading_method",
  183. "set_back_interior_shading_method",
  184. "set_reflectance_model",
  185. "set_back_reflectance_model",
  186. "set_surface_approximation_criteria",
  187. "set_parametric_surface_characteristics",
  188. "set_face_distinguishing_mode",
  189. "set_face_culling_mode",
  190. "set_light_source_state",
  191. "set_depth_cue_index",
  192. "set_colour_mapping_index",
  193. "set_rendering_colour_model",
  194. #endif
  195. };
  196.  
  197. static char *attrlist[] =
  198. {
  199. "polyline",
  200. "polymarker",
  201. "text",
  202. "interior",
  203. "edge"
  204. };
  205.  
  206. #ifdef HP
  207. static Pstore hpstore;
  208. static ptkboolean hpstorecreated = FALSE;
  209. #endif
  210.  
  211. /*--------------------------------------------------------------------------*/
  212. /*---------------------- Input Functions -----------------------------------*/
  213.  
  214. static void ptk_setstringprompt(C(Pint) ws, C(char *) prompt, 
  215.                                 C(Plimit *) echoarea)
  216. PreANSI(Pint ws)
  217. PreANSI(char *prompt)
  218. PreANSI(Plimit *echoarea)
  219. /*
  220. ** \parambegin
  221. ** \param{}{ws}{workstation identifier}{IN}
  222. ** \param{}{size}{size of the device buffer}{IN}
  223. ** \param{}{prompt}{prompt string}{IN}
  224. ** \paramend
  225. ** \blurb{Initialises the string device to use prompt 'prompt'.}
  226. */
  227. {
  228.   Pstring_data stringrec;
  229.  
  230.   /* Implementation dependent code */
  231.   stringrec.in_buf_size = 80;
  232.   stringrec.init_pos = strlen(prompt) + 1;
  233. #ifdef HP
  234.   stringrec.pets.pet_r1.text_colr_ind = 1;
  235. #endif
  236.   /* set the echo area to be sensible percentage of device space */
  237.   pinit_string(ws, 1, prompt, 1, echoarea, &stringrec);
  238.   pset_string_mode(ws, 1, POP_REQ, PSWITCH_ECHO);
  239. }  /* ptk_setstringprompt */
  240.  
  241. /*--------------------------------------------------------------------------*/
  242.  
  243. /*function:external*/
  244. extern Pint ptk_readint(C(Pint) ws, C(Pint) defint, C(char *) prompt,
  245.                         C(Plimit *) echoarea)
  246. PreANSI(Pint ws)
  247. PreANSI(Pint defint)
  248. PreANSI(char *prompt)
  249. PreANSI(Plimit *echoarea)
  250. /*
  251. ** \parambegin
  252. ** \param{Pint}{ws}{workstation identifier}{IN}
  253. ** \param{Pint}{defint}{default integer}{IN}
  254. ** \param{char *}{prompt}{prompt string}{IN}
  255. ** \param{Plimit *}{echoarea}{string echo area}{IN}
  256. ** \paramend
  257. ** \blurb{This function reads and returns  an integer from 
  258. ** string device 1 on workstation \pardesc{ws},
  259. ** using \pardesc{prompt} as a prompt string.
  260. ** If the user types a carriage-return instead of supplying an
  261. ** integer, the function returns the specified default value \pardesc{defint}.
  262. ** \pardesc{echoarea} specifies the echo area to use for the string device.}
  263. */
  264. {
  265.   Pin_status status;
  266.   char *str;
  267.   Pint val;
  268.   Pint size;
  269.   Pint pos;
  270.  
  271.   ptk_setstringprompt(ws, prompt, echoarea);
  272.   pos = strlen(prompt);
  273.   str = NULL;
  274.   size = 80;
  275.   str = (char *)malloc(size);  
  276.   preq_string(ws, 1, &status, str);
  277.   if (status == PIN_STATUS_OK)
  278.   {
  279.     if (str[pos] == '\0')
  280.       val = defint;
  281.     else
  282.       val = atoi(&str[pos]);
  283.     free(str);
  284.     return val;
  285.   }
  286.   else
  287.   {
  288.     free(str);
  289.     return defint; 
  290.   }
  291. }  /* ptk_readint */
  292.  
  293. /*--------------------------------------------------------------------------*/
  294.  
  295. /*function:external*/
  296. extern Pfloat ptk_readfloat(C(Pint) ws, C(Pfloat) defreal,
  297.                         C(char *) prompt, C(Plimit *) echoarea)
  298. PreANSI(Pint ws)
  299. PreANSI(Pfloat defreal)
  300. PreANSI(char *prompt)
  301. PreANSI(Plimit *echoarea)
  302. /*
  303. ** \parambegin
  304. ** \param{Pint}{ws}{workstation identifier}{IN}
  305. ** \param{Pfloat}{defreal}{default floating point number}{IN}
  306. ** \param{char *}{prompt}{prompt string}{IN}
  307. ** \param{Plimit *}{echoarea}{string echo area}{IN}
  308. ** \paramend
  309. ** \blurb{This function reads and returns a real number from 
  310. ** string device 1 on workstation \pardesc{ws},
  311. ** using \pardesc{prompt} as a prompt string.
  312. ** If the user types a carriage-return instead of supplying an
  313. ** real value, the function returns the specified default value \pardesc{defreal}.
  314. ** \pardesc{echoarea} specifies the echo area to use for the string device.}
  315. */
  316. {
  317.   Pin_status status;
  318.   char *str;
  319.   Pfloat val;
  320.   Pint size;
  321.   Pint pos;
  322.  
  323.   ptk_setstringprompt(ws, prompt, echoarea);
  324.   pos = strlen(prompt);
  325.   str = NULL;
  326.   size = 80;
  327.   str = (char *)malloc(size);  
  328.   preq_string(ws, 1, &status, str);
  329.   if (status == PIN_STATUS_OK)
  330.   {
  331.     if (str[pos] == '\0')
  332.       val = defreal;
  333.     else
  334.       val = atof(&str[pos]);
  335.     free(str);
  336.     return val;
  337.   }
  338.   else
  339.   {
  340.     free(str);
  341.     return defreal; 
  342.   }
  343. }  /* ptk_readfloat */
  344.  
  345. /*--------------------------------------------------------------------------*/
  346.  
  347. /*function:external*/
  348. extern void ptk_readstring(C(Pint) ws, C(char *) defstring,
  349.                            C(char *) prompt, C(Plimit *) echoarea,
  350.                            C(Pint) len, C(char *) instr, C(Pint *) inlen)
  351. PreANSI(Pint ws)
  352. PreANSI(char *defstring)
  353. PreANSI(char *prompt)
  354. PreANSI(Plimit *echoarea)
  355. PreANSI(Pint len)
  356. PreANSI(char *instr) 
  357. PreANSI(Pint *inlen)
  358. /*
  359. ** \parambegin
  360. ** \param{Pint}{ws}{workstation identifier}{IN}
  361. ** \param{char *}{defstring}{default string}{IN}
  362. ** \param{char *}{prompt}{prompt string}{IN}
  363. ** \param{Plimit *}{echoarea}{string echo area}{IN}
  364. ** \param{Pint}{len}{number of characters allocated for input string}{IN}
  365. ** \param{char *}{instr}{input string}{OUT}
  366. ** \param{Pint *}{inlen}{length of input string}{OUT}
  367. ** \paramend
  368. ** \blurb{This function reads and returns a real number from 
  369. ** string device 1 on workstation \pardesc{ws},
  370. ** using \pardesc{prompt} as a prompt string.
  371. ** If the user types a carriage-return instead of supplying a
  372. ** string, the function returns the specified default value \pardesc{defstring}.
  373. ** \pardesc{echoarea} specifies the echo area to use for the string device.}
  374. */
  375. {
  376.   Pin_status status;
  377.   char *str;
  378.   Pint size;
  379.   Pint pos;
  380.  
  381.   ptk_setstringprompt(ws, prompt, echoarea);
  382.   pos = strlen(prompt);
  383.   str = NULL;
  384.   size = 80;
  385.   str = (char *)malloc(size);
  386.   preq_string(ws, 1, &status, str);
  387.   /* Implementation dependent - PEX-SI returns '\n\0' at the end of every
  388.   ** string when using string input. Replace the \n with \0.
  389.   */
  390. #ifdef PEXSI
  391.   str[strlen(str) - 1] = '\0';
  392. #endif
  393.   if (status == PIN_STATUS_OK)
  394.   {
  395.     if (str[pos] == '\0')
  396.     {
  397.       strncpy(instr, defstring, len);
  398.       *inlen = strlen(defstring);
  399.       free(str);
  400.     }
  401.     else
  402.     {
  403.       strncpy(instr, &str[pos], len);
  404. #ifndef PEXSI
  405.       *inlen = strlen(instr);
  406. #endif
  407. #ifdef PEXSI
  408.       *inlen = strlen(instr) - 1;
  409. #endif
  410.       free(str);
  411.     }
  412.   }
  413.   else
  414.   {
  415.     strncpy(instr, defstring, len);
  416.     *inlen = strlen(defstring);
  417.     free(str);
  418.   }
  419. }  /* ptk_readstring */
  420.  
  421. /*--------------------------------------------------------------------------*/
  422. /*------------------------ Structure Functions -----------------------------*/
  423.  
  424. /*function:external*/
  425. extern void ptk_stackstruct(C(void))
  426. /* PreANSI() */
  427. /*
  428. ** \blurb{This function stores the name
  429. **  of the currently open structure, and the position of the element pointer on the
  430. ** structure
  431. ** stack, and closes the structure}
  432. */
  433. {
  434.   Pint err, stid;
  435.   Popen_struct_status structstatus;
  436.   ptksstructstack *stackitem;
  437.  
  438.   pinq_open_struct(&err, &structstatus, &stid);
  439.   if ((err == 0) && (structstatus == PSTRUCT_OPEN))
  440.   {
  441.     stackitem = (ptksstructstack *)malloc(sizeof(ptksstructstack));
  442.     stackitem->next = structstack;
  443.     structstack = stackitem;
  444.     stackitem->structid = stid;
  445.     pinq_elem_ptr(&err, &stackitem->elemptr);
  446.     pclose_struct();
  447.   }
  448. }  /* ptk_stackstruct */
  449.  
  450. /*--------------------------------------------------------------------------*/
  451.  
  452. /*function:external*/
  453. extern void ptk_unstackstruct(C(void))
  454. /* PreANSI() */
  455. /*
  456. ** \blurb{This function pops the structure stack,
  457. **  opens the structure and sets the element pointer.}
  458. */
  459. {
  460.   ptksstructstack *stackitem;
  461.  
  462.   if (structstack != NULL)
  463.   {
  464.     popen_struct(structstack->structid);
  465.     pset_elem_ptr(structstack->elemptr);
  466.     stackitem = structstack->next;
  467.     free(structstack);
  468.     structstack = stackitem;
  469.   }
  470. }  /* ptk_unstackstruct */
  471.  
  472. /*--------------------------------------------------------------------------*/
  473.  
  474. /*function:external*/
  475. extern void ptk_openstruct(C(Pint) structid)
  476. PreANSI(Pint structid)
  477. /*
  478. ** \parambegin
  479. ** \param{Pint}{structid}{structure identifier}{IN}
  480. ** \paramend
  481. ** \blurb{This function stores the currently open structure and element
  482. **  pointer on a stack and opens the structure {\tt structid}.}
  483. */
  484. {
  485.   Pint err, stid;
  486.   Popen_struct_status structstatus;
  487.   ptksstructstack *stackitem;
  488.  
  489.   ptk_stackstruct();
  490.   popen_struct(structid);
  491. }  /* ptk_openstruct */
  492.  
  493. /*--------------------------------------------------------------------------*/
  494.  
  495. /*function:external*/
  496. extern void ptk_closestruct(C(void))
  497. /* PreANSI() */
  498. /*
  499. ** \blurb{This function closes the currently open structure, and restores the open
  500. ** structure and element pointer from the structure stack.}
  501. */
  502. {
  503.   pclose_struct();
  504.   ptk_unstackstruct();
  505. }  /* ptk_closestruct */
  506.  
  507. /*--------------------------------------------------------------------------*/
  508.  
  509. /*function:external*/
  510. extern void ptk_seteditmode(C(Pedit_mode) editmode)
  511. PreANSI(Pedit_mode editmode)
  512. /*
  513. ** \parambegin
  514. ** \param{Pedit\_mode}{editmode}{edit mode}{IN}
  515. ** \paramend
  516. ** \blurb{This function stores
  517. **  the current edit mode on the editmode stack and then sets the edit mode
  518. ** to given value.}
  519. */
  520. {
  521.   Pint err;
  522.   Pedit_mode emode;
  523.   Popen_struct_status structstatus;
  524.   ptkseditmodestack *stackitem;
  525.  
  526.   pinq_edit_mode(&err, &emode);
  527.   if (err == 0)
  528.   {
  529.     stackitem = (ptkseditmodestack *)malloc(sizeof(ptkseditmodestack));
  530.     stackitem->next = editmodestack;
  531.     editmodestack = stackitem;
  532.     stackitem->editmode = emode;
  533.   }
  534.   pset_edit_mode(editmode);
  535. }  /* ptk_seteditmode */
  536.  
  537. /*--------------------------------------------------------------------------*/
  538.  
  539. /*function:external*/
  540. extern void ptk_unseteditmode(C(void))
  541. /* PreANSI() */
  542. /*
  543. ** \parambegin
  544. ** \paramend
  545. ** \blurb{This function restores the current edit mode from the edit mode stack.}
  546. */
  547. {
  548.   ptkseditmodestack *stackitem;
  549.  
  550.   if (editmodestack != NULL)
  551.   {
  552.     pset_edit_mode(editmodestack->editmode);
  553.     stackitem = editmodestack->next;
  554.     free(editmodestack);
  555.     editmodestack = stackitem;
  556.   }
  557. }  /* ptk_unseteditmode */
  558.  
  559. /*--------------------------------------------------------------------------*/
  560.  
  561. /*function:external*/
  562. extern ptkboolean ptk_getpickid(C(Pint) stid, C(Pint) elptr, C(Pint *) pickid)
  563. PreANSI(Pint stid)
  564. PreANSI(Pint elptr)
  565. PreANSI(Pint *pickid)
  566. /*
  567. ** \parambegin
  568. ** \param{Pint}{stid}{structure identifier}{IN}
  569. ** \param{Pint}{elptr}{element pointer value}{IN}
  570. ** \param{Pint *}{pickid}{pick identifier}{OUT}
  571. ** \paramend
  572. ** \blurb{This function inquires the pick identifier at the element position
  573. ** specified by \pardesc{elptr} in
  574. **  structure \pardesc{stid}.
  575. ** The result of the function is TRUE if the element was a pick
  576. **  identifier, otherwise FALSE.}
  577. */
  578. {
  579.   ptkboolean result;
  580.   Pint err;
  581.   Pstore store;
  582.   ptkselcontent elcont;
  583.  
  584.   pcreate_store(&err, &store);
  585.   ptk_inqelemtypesizecontent(stid, elptr, store, &err, &elcont);
  586.   if (elcont.eltype == PELEM_PICK_ID) 
  587.   {
  588.     result = TRUE;
  589.     *pickid = elcont.eldata->int_data;
  590.   } 
  591.   else
  592.     result = FALSE;
  593.   ptk_delstore(store);
  594.   return result;
  595. }  /* ptk_getpickid */
  596.  
  597. /*--------------------------------------------------------------------------*/
  598.  
  599. /*function:external*/
  600. extern ptkboolean ptk_getexecuteid(C(Pint) stid, C(Pint) elptr, C(Pint *) execid)
  601. PreANSI(Pint stid)
  602. PreANSI(Pint elptr)
  603. PreANSI(Pint *execid)
  604. /*
  605. ** \parambegin
  606. ** \param{Pint}{stid}{structure identifier}{IN}
  607. ** \param{Pint}{elptr}{element pointer value}{IN}
  608. ** \param{Pint *}{execid}{execute structure identifier}{OUT}
  609. ** \paramend
  610. ** \blurb{This function inquires the execute element
  611. **  identifier at the element position
  612. ** specified by \pardesc{elptr} in
  613. **  structure \pardesc{stid}.
  614. ** The result of the function is TRUE if the element was an execute
  615. **  element, otherwise FALSE..}
  616. */
  617. {
  618.   ptkboolean result;
  619.   Pint err;
  620.   Pstore store;
  621.   ptkselcontent elcont;
  622.  
  623.   pcreate_store(&err, &store);
  624.   ptk_inqelemtypesizecontent(stid, elptr, store, &err, &elcont);
  625.   if (elcont.eltype == PELEM_EXEC_STRUCT) 
  626.   {
  627.     result = TRUE;
  628.     *execid = elcont.eldata->int_data;
  629.   } 
  630.   else
  631.     result = FALSE;
  632.   ptk_delstore(store);
  633.   return result;
  634. }  /* ptk_getexecuteid */
  635.  
  636. /*--------------------------------------------------------------------------*/
  637.  
  638. /*function:external*/
  639. extern Pint ptk_elemcount(C(Pint) stid)
  640. PreANSI(Pint stid)
  641. /*
  642. ** \parambegin
  643. ** \param{Pint}{stid}{structure identifier}{IN}
  644. ** \paramend
  645. ** \blurb{This functions counts the number of elements 
  646. ** in  structure \pardesc{stid},
  647. ** returning  the number of elements, or -1 if the structure does
  648. ** not exist.}
  649. */
  650. {
  651.   Pint result;
  652.   Pstruct_status stat;
  653.   Pint openst;
  654.   Popen_struct_status openstat;
  655.   Pint err, p, oldp;
  656.  
  657.   result = 0;
  658.   pinq_struct_status(stid, &err, &stat);
  659.   if (stat == PSTRUCT_STATUS_NON_EXISTENT)
  660.     return -1;
  661.   if (stat == PSTRUCT_STATUS_EMPTY)
  662.     return 0;
  663.   ptk_openstruct(stid);
  664.   pinq_elem_ptr(&err, &p);
  665.   result = p;
  666.   ptk_closestruct();
  667.   return result;
  668. }  /* ptk_elemcount */
  669.  
  670. /*--------------------------------------------------------------------------*/
  671.  
  672. /*function:external*/
  673. extern ptkboolean ptk_structexists(C(Pint) stid)
  674. PreANSI(Pint stid)
  675. /*
  676. ** \parambegin
  677. ** \param{Pint}{stid}{structure identifier}{IN}
  678. ** \paramend
  679. ** \blurb{This function checks if structure \pardesc{stid} exists in the CSS,
  680. ** returning TRUE if it exists, otherwise FALSE.}
  681. */
  682. {
  683.   Pstruct_status structstat;
  684.   Pint err;
  685.  
  686.   pinq_struct_status(stid, &err, &structstat);
  687.   if (err == 0)
  688.     return (structstat != PSTRUCT_STATUS_NON_EXISTENT);
  689.   else
  690.     return FALSE;
  691. }  /* ptk_structexists */
  692.  
  693. /*--------------------------------------------------------------------------*/
  694.  
  695. /*function:external*/
  696. extern void ptk_getelemtype(C(char *) elemstr, C(Pelem_type *) eltype)
  697. PreANSI(char *elemstr)
  698. PreANSI(Pelem_type *eltype)
  699. /*
  700. ** \parambegin
  701. ** \param{char *}{elemstr}{string giving element type}{IN}
  702. ** \param{Pelem\_type *}{eltype}{element type}{OUT}
  703. ** \paramend
  704. ** \blurb{This function converts the string \pardesc{elemstr}
  705. ** into its corresponding element type. For example the element type for
  706. **  "polyline3", would be PEL\_POLYLINE3.}
  707. */
  708. {  
  709.   Pint ind;
  710.  
  711.   ind = instrlist(elemlist, NUMPHIGSELEMS, elemstr);
  712.   if (ind >= 0)
  713.     *eltype = (Pelem_type)ind;
  714.   else
  715.     *eltype = PELEM_NIL;
  716. }  /* ptk_getelemtype */
  717.  
  718. /*--------------------------------------------------------------------------*/
  719.  
  720. /*function:external*/
  721. extern void ptk_getelemtypename(C(Pelem_type) eltype, C(Pint) size, 
  722.                      C(char *) elemstr, C(Pint *) totalsize)
  723. PreANSI(Pelem_type eltype)
  724. PreANSI(Pint size)
  725. PreANSI(char *elemstr)
  726. PreANSI(Pint *totalsize)
  727. /*
  728. ** \parambegin
  729. ** \param{Pelem\_type}{eltype}{element type}{IN}
  730. ** \param{Pint}{size}{size of buffer allocated by application}{IN}
  731. ** \param{char *}{elemstr}{string giving element type}{OUT}
  732. ** \param{Pint *}{totalsize}{length of string}{OUT}
  733. ** \paramend
  734. ** \blurb{This function converts element type \pardesc{eltype}
  735. **  into the corresponding character string, which is returned in
  736. ** \pardesc{elemstr}. For example, the string corresponding to
  737. ** PE\_POLYLINE3 would be "polyline3".}
  738. */
  739. {
  740.   *totalsize = strlen(elemlist[(Pint)eltype]) + 1;
  741.    if (*totalsize <= size)
  742.      strncpy(elemstr, elemlist[(Pint)eltype], *totalsize);  
  743. }  /* ptk_getelemtypename */
  744.  
  745. /*--------------------------------------------------------------------------*/
  746.  
  747. /*function:external*/
  748. extern void ptk_executeelem(C(ptkselcontent *) elcont)
  749. PreANSI(ptkselcontent *elcont)
  750. /*
  751. ** \parambegin
  752. ** \param{ptkselcontent *}{elcont}{element content}{IN}
  753. ** \paramend
  754. ** \blurb{This function creates a structure element which has the
  755. **  contents \pardesc{elcont}. The element is inserted into the currently open
  756. ** structure.}
  757. */
  758. {
  759.   switch (elcont->eltype) 
  760.   {
  761.       case PELEM_POLYLINE3:
  762.         ppolyline3(&elcont->eldata->point_list3);
  763.         break;
  764.  
  765.       case PELEM_POLYLINE:
  766.         ppolyline(&elcont->eldata->point_list);
  767.         break;
  768.  
  769.       case PELEM_POLYMARKER3:
  770.         ppolymarker3(&elcont->eldata->point_list3);
  771.         break;
  772.  
  773.       case PELEM_POLYMARKER:
  774.         ppolymarker(&elcont->eldata->point_list);
  775.         break;
  776.  
  777.       case PELEM_TEXT3:
  778.         ptext3(&elcont->eldata->text3.pos, elcont->eldata->text3.dir, 
  779.                elcont->eldata->text3.char_string);
  780.         break;
  781.  
  782.       case PELEM_TEXT:
  783.         ptext(&elcont->eldata->text.pos, elcont->eldata->text.char_string);
  784.         break;
  785.  
  786.       case PELEM_ANNO_TEXT_REL3:
  787.         panno_text_rel3(&elcont->eldata->anno_text_rel3.ref_point, 
  788.                                  &elcont->eldata->anno_text_rel3.offset, 
  789.                                  elcont->eldata->anno_text_rel3.char_string);
  790.         break;
  791.  
  792.       case PELEM_ANNO_TEXT_REL:
  793.         panno_text_rel(&elcont->eldata->anno_text_rel.ref_point, 
  794.                                 &elcont->eldata->anno_text_rel.offset, 
  795.                                 elcont->eldata->anno_text_rel.char_string);
  796.         break;
  797.  
  798.       case PELEM_FILL_AREA3:
  799.         pfill_area3(&elcont->eldata->point_list3);
  800.         break;
  801.  
  802.       case PELEM_FILL_AREA:
  803.         pfill_area(&elcont->eldata->point_list);
  804.         break;
  805.  
  806.       case PELEM_FILL_AREA_SET3:
  807.         pfill_area_set3(&elcont->eldata->point_list_list3);
  808.         break;
  809.  
  810.       case PELEM_FILL_AREA_SET:
  811.         pfill_area_set(&elcont->eldata->point_list_list);
  812.         break;
  813.  
  814.       case PELEM_CELL_ARRAY3:
  815. #ifndef HP
  816.         pcell_array3(&elcont->eldata->cell_array3.paral, 
  817.                      &elcont->eldata->cell_array3.colr_array);
  818. #endif
  819.         break;
  820.  
  821.       case PELEM_CELL_ARRAY:
  822. #ifndef HP
  823.         pcell_array(&elcont->eldata->cell_array.rect, 
  824.                    &elcont->eldata->cell_array.colr_array);
  825. #endif
  826.         break;
  827.  
  828.       case PELEM_GDP3:
  829.         pgdp3(&elcont->eldata->gdp3.point_list, 
  830.               elcont->eldata->gdp3.id, &elcont->eldata->gdp3.data);
  831.         break;
  832.  
  833.       case PELEM_GDP:
  834.         pgdp(&elcont->eldata->gdp.point_list, 
  835.              elcont->eldata->gdp.id, &elcont->eldata->gdp.data);
  836.         break;
  837.  
  838.       case PELEM_LINE_IND:
  839.         pset_line_ind(elcont->eldata->int_data);
  840.         break;
  841.  
  842.       case PELEM_MARKER_IND:
  843.         pset_marker_ind(elcont->eldata->int_data);
  844.         break;
  845.  
  846.       case PELEM_TEXT_IND:
  847.         pset_text_ind(elcont->eldata->int_data);
  848.         break;
  849.  
  850.       case PELEM_INT_IND:
  851.         pset_int_ind(elcont->eldata->int_data);
  852.         break;
  853.  
  854.       case PELEM_EDGE_IND:
  855.         pset_edge_ind(elcont->eldata->int_data);
  856.         break;
  857.  
  858.       case PELEM_LINETYPE:
  859.         pset_linetype(elcont->eldata->int_data);
  860.         break;
  861.  
  862.       case PELEM_LINEWIDTH:
  863.         pset_linewidth(elcont->eldata->float_data);
  864.         break;
  865.  
  866.       case PELEM_LINE_COLR_IND:
  867.         pset_line_colr_ind(elcont->eldata->int_data);
  868.         break;
  869.  
  870.       case PELEM_MARKER_TYPE:
  871.         pset_marker_type(elcont->eldata->int_data);
  872.         break;
  873.  
  874.       case PELEM_MARKER_SIZE:
  875.         pset_marker_size(elcont->eldata->float_data);
  876.         break;
  877.  
  878.       case PELEM_MARKER_COLR_IND:
  879.         pset_marker_colr_ind(elcont->eldata->int_data);
  880.         break;
  881.  
  882.       case PELEM_TEXT_FONT:
  883.         pset_text_font(elcont->eldata->int_data);
  884.         break;
  885.  
  886.       case PELEM_TEXT_PREC:
  887.         pset_text_prec(elcont->eldata->text_prec);
  888.         break;
  889.  
  890.       case PELEM_CHAR_EXPAN:
  891.         pset_char_expan(elcont->eldata->float_data);
  892.         break;
  893.  
  894.       case PELEM_CHAR_SPACE:
  895.         pset_char_space(elcont->eldata->float_data);
  896.         break;
  897.  
  898.       case PELEM_TEXT_COLR_IND:
  899.         pset_text_colr_ind(elcont->eldata->int_data);
  900.         break;
  901.  
  902.       case PELEM_CHAR_HT:
  903.         pset_char_ht(elcont->eldata->float_data);
  904.         break;
  905.  
  906.       case PELEM_CHAR_UP_VEC:
  907.         pset_char_up_vec(&elcont->eldata->char_up_vec);
  908.         break;
  909.  
  910.       case PELEM_TEXT_PATH:
  911.         pset_text_path(elcont->eldata->text_path);
  912.         break;
  913.  
  914.       case PELEM_TEXT_ALIGN:
  915.         pset_text_align(&elcont->eldata->text_align);
  916.         break;
  917.  
  918.       case PELEM_ANNO_CHAR_HT:
  919.         pset_anno_char_ht(elcont->eldata->float_data);
  920.         break;
  921.  
  922.       case PELEM_ANNO_CHAR_UP_VEC:
  923.         pset_anno_char_up_vec(&elcont->eldata->char_up_vec);
  924.         break;
  925.  
  926.       case PELEM_ANNO_PATH:
  927.         pset_anno_path(elcont->eldata->text_path);
  928.         break;
  929.  
  930.       case PELEM_ANNO_ALIGN:
  931.         pset_anno_align(&elcont->eldata->text_align);
  932.         break;
  933.  
  934.       case PELEM_ANNO_STYLE:
  935.         pset_anno_style(elcont->eldata->int_data);
  936.         break;
  937.     
  938.       case PELEM_INT_STYLE:
  939.         pset_int_style(elcont->eldata->int_data);
  940.         break;
  941.  
  942.       case PELEM_INT_STYLE_IND:
  943.         pset_int_style_ind(elcont->eldata->int_data);
  944.         break;
  945.  
  946.       case PELEM_INT_COLR_IND:
  947.         pset_int_colr_ind(elcont->eldata->int_data);
  948.         break;
  949.  
  950.       case PELEM_EDGE_FLAG:
  951.         pset_edge_flag(elcont->eldata->edge_flag);
  952.         break;
  953.  
  954.       case PELEM_EDGETYPE:
  955.         pset_edgetype(elcont->eldata->int_data);
  956.         break;
  957.  
  958.       case PELEM_EDGEWIDTH:
  959.         pset_edgewidth(elcont->eldata->float_data);
  960.         break;
  961.  
  962.       case PELEM_EDGE_COLR_IND:
  963.         pset_edge_colr_ind(elcont->eldata->int_data);
  964.         break;
  965.  
  966.       case PELEM_PAT_SIZE:
  967. #ifndef HP
  968.         pset_pat_size(elcont->eldata->pat_size.size_x,
  969.                       elcont->eldata->pat_size.size_y);
  970. #endif
  971.         break;
  972.  
  973.       case PELEM_PAT_REF_POINT_VECS:
  974. #ifndef HP
  975.         pset_pat_ref_point_vecs(&elcont->eldata->pat_ref_point_vecs.ref_point,
  976.                                 elcont->eldata->pat_ref_point_vecs.ref_vec);
  977. #endif
  978.         break;
  979.  
  980.       case PELEM_PAT_REF_POINT:
  981. #ifndef HP
  982.         pset_pat_ref_point(&elcont->eldata->pat_ref_point);
  983. #endif
  984.         break;
  985.  
  986.       case PELEM_ADD_NAMES_SET:
  987.         padd_names_set(&elcont->eldata->names);
  988.         break;
  989.  
  990.       case PELEM_REMOVE_NAMES_SET:
  991.         premove_names_set(&elcont->eldata->names);
  992.         break;
  993.  
  994.       case PELEM_INDIV_ASF:
  995.         pset_indiv_asf(elcont->eldata->asf.id, elcont->eldata->asf.source);
  996.         break;
  997.  
  998.       case PELEM_HLHSR_ID:
  999.         pset_hlhsr_id(elcont->eldata->int_data);
  1000.         break;
  1001.  
  1002.       case PELEM_LOCAL_MODEL_TRAN3:
  1003.         pset_local_tran3(elcont->eldata->local_tran3.matrix, 
  1004.                          elcont->eldata->local_tran3.compose_type);
  1005.         break;
  1006.  
  1007.       case PELEM_LOCAL_MODEL_TRAN:
  1008.         pset_local_tran(elcont->eldata->local_tran.matrix, 
  1009.                         elcont->eldata->local_tran.compose_type);
  1010.         break;
  1011.  
  1012.       case PELEM_GLOBAL_MODEL_TRAN3:
  1013.         pset_global_tran3(elcont->eldata->global_tran3);
  1014.         break;
  1015.  
  1016.       case PELEM_GLOBAL_MODEL_TRAN:
  1017.         pset_global_tran(elcont->eldata->global_tran);
  1018.         break;
  1019.  
  1020.       case PELEM_MODEL_CLIP_VOL3:
  1021.         pset_model_clip_vol3(elcont->eldata->model_clip3.op, 
  1022.                              &elcont->eldata->model_clip3.half_spaces);
  1023.         break;
  1024.  
  1025.       case PELEM_MODEL_CLIP_VOL:
  1026.         pset_model_clip_vol(elcont->eldata->model_clip.op, 
  1027.                             &elcont->eldata->model_clip.half_spaces);
  1028.         break;
  1029.  
  1030.       case PELEM_MODEL_CLIP_IND:
  1031.         pset_model_clip_ind(elcont->eldata->clip_ind);
  1032.         break;
  1033.  
  1034.       case PELEM_RESTORE_MODEL_CLIP_VOL:
  1035.         prestore_model_clip_vol();
  1036.         break;
  1037.  
  1038.       case PELEM_VIEW_IND:
  1039.         pset_view_ind(elcont->eldata->int_data);
  1040.         break;
  1041.  
  1042.       case PELEM_EXEC_STRUCT:
  1043.         pexec_struct(elcont->eldata->int_data);
  1044.         break;
  1045.  
  1046.       case PELEM_LABEL:
  1047.         plabel(elcont->eldata->int_data);
  1048.         break;
  1049.  
  1050.       case PELEM_APPL_DATA:
  1051.         pappl_data(&elcont->eldata->appl_data);
  1052.         break;
  1053.  
  1054.       case PELEM_GSE:
  1055.         pgse(elcont->eldata->gse.id, &elcont->eldata->gse.data);
  1056.         break;
  1057.  
  1058.       case PELEM_PICK_ID:
  1059.         pset_pick_id(elcont->eldata->int_data);
  1060.         break;
  1061.  
  1062.       /* PHIGS PLUS bits */
  1063. #ifdef SUN
  1064.       case PELEM_POLYLINE_SET3_DATA:
  1065.         ppolyline_set3_data(elcont->eldata->plsd3.vflag,
  1066.            elcont->eldata->plsd3.colr_model, elcont->eldata->plsd3.npl,
  1067.            elcont->eldata->plsd3.vdata);
  1068.         break;
  1069.  
  1070.       case PELEM_FILL_AREA_SET3_DATA:
  1071.         pfill_area_set3_data(elcont->eldata->fasd3.fflag,
  1072.            elcont->eldata->fasd3.eflag, elcont->eldata->fasd3.vflag,
  1073.            elcont->eldata->fasd3.colr_model, 
  1074.            &elcont->eldata->fasd3.fdata, elcont->eldata->fasd3.nfa,
  1075.            elcont->eldata->fasd3.edata, elcont->eldata->fasd3.vdata);
  1076.         break;
  1077.  
  1078.       case PELEM_TRI_STRIP3_DATA:
  1079.         ptri_strip3_data(elcont->eldata->tsd3.fflag, 
  1080.            elcont->eldata->tsd3.vflag, elcont->eldata->tsd3.colr_model,
  1081.            elcont->eldata->tsd3.nv, &elcont->eldata->tsd3.fdata,
  1082.            &elcont->eldata->tsd3.vdata);
  1083.         break;
  1084.  
  1085.       case PELEM_QUAD_MESH3_DATA:
  1086.         pquad_mesh3_data(elcont->eldata->qmd3.fflag,
  1087.            elcont->eldata->qmd3.vflag, elcont->eldata->qmd3.colr_model,
  1088.            &elcont->eldata->qmd3.dim, &elcont->eldata->qmd3.fdata,
  1089.            &elcont->eldata->qmd3.vdata);
  1090.         break;
  1091.  
  1092.       case PELEM_SET_OF_FILL_AREA_SET3_DATA:
  1093.         pset_of_fill_area_set3_data(elcont->eldata->sofas3.fflag,
  1094.            elcont->eldata->sofas3.eflag, elcont->eldata->sofas3.vflag,
  1095.            elcont->eldata->sofas3.colr_model, 
  1096.            elcont->eldata->sofas3.num_sets, &elcont->eldata->sofas3.fdata,
  1097.            elcont->eldata->sofas3.edata, elcont->eldata->sofas3.vlist,
  1098.            &elcont->eldata->sofas3.vdata);
  1099.         break;
  1100.  
  1101.       case PELEM_NUNI_BSP_CURVE:
  1102.         pnuni_bsp_curv(elcont->eldata->nurb_curve.order,
  1103.            &elcont->eldata->nurb_curve.knots,
  1104.            elcont->eldata->nurb_curve.rationality,
  1105.            &elcont->eldata->nurb_curve.cpts,
  1106.            elcont->eldata->nurb_curve.min, elcont->eldata->nurb_curve.max);
  1107.         break;
  1108.  
  1109.       case PELEM_NUNI_BSP_SURF:
  1110.         pnuni_bsp_surf(elcont->eldata->nurb_surf.u_order,
  1111.            elcont->eldata->nurb_surf.v_order,
  1112.            &elcont->eldata->nurb_surf.uknots,
  1113.            &elcont->eldata->nurb_surf.vknots,
  1114.            elcont->eldata->nurb_surf.rationality,
  1115.            &elcont->eldata->nurb_surf.grid,
  1116.            elcont->eldata->nurb_surf.num_trim_loops,
  1117.            elcont->eldata->nurb_surf.trim_loops);
  1118.         break;
  1119.  
  1120.       case PELEM_CELL_ARRAY3_PLUS:
  1121.         pcell_array3_plus(&elcont->eldata->cell_array_plus.paral,
  1122.            &elcont->eldata->cell_array_plus.colr_array.dims,
  1123.            elcont->eldata->cell_array_plus.colr_array.type,
  1124.            elcont->eldata->cell_array_plus.colr_array.colr_array);
  1125.         break;
  1126.  
  1127.       case PELEM_TEXT_COLR:
  1128.         pset_text_colr(&elcont->eldata->colr);
  1129.         break;
  1130.  
  1131.       case PELEM_MARKER_COLR:
  1132.         pset_marker_colr(&elcont->eldata->colr);
  1133.         break;
  1134.  
  1135.       case PELEM_EDGE_COLR:
  1136.         pset_edge_colr(&elcont->eldata->colr);
  1137.         break;
  1138.  
  1139.       case PELEM_LINE_COLR:
  1140.         pset_line_colr(&elcont->eldata->colr);
  1141.         break;
  1142.  
  1143.       case PELEM_CURVE_APPROX_CRIT:
  1144.         pset_curve_approx(elcont->eldata->curv_approx.type,
  1145.                           elcont->eldata->curv_approx.value);
  1146.         break;
  1147.  
  1148.       case PELEM_LINE_SHAD_METH:
  1149.         pset_line_shad_meth(elcont->eldata->int_data);
  1150.         break;
  1151.  
  1152.       case PELEM_INT_COLR:
  1153.         pset_int_colr(&elcont->eldata->colr);
  1154.         break;
  1155.  
  1156.       case PELEM_BACK_INT_COLR:
  1157.         pset_back_int_colr(&elcont->eldata->colr);
  1158.         break;
  1159.  
  1160.       case PELEM_BACK_INT_STYLE:
  1161.         pset_back_int_style(elcont->eldata->int_style);
  1162.         break;
  1163.  
  1164.       case PELEM_BACK_INT_STYLE_IND:
  1165.         pset_back_int_style_ind(elcont->eldata->int_data);
  1166.         break;
  1167.  
  1168.       case PELEM_REFL_PROPS:
  1169.         pset_refl_props(&elcont->eldata->props);
  1170.         break;
  1171.  
  1172.       case PELEM_BACK_REFL_PROPS:
  1173.         pset_back_refl_props(&elcont->eldata->props);
  1174.         break;
  1175.  
  1176.       case PELEM_INT_SHAD_METH:
  1177.         pset_int_shad_meth(elcont->eldata->int_data);
  1178.         break;
  1179.  
  1180.       case PELEM_BACK_INT_SHAD_METH:
  1181.         pset_back_int_shad_meth(elcont->eldata->int_data);
  1182.         break;
  1183.  
  1184.       case PELEM_INT_REFL_EQN:
  1185.         pset_refl_eqn(elcont->eldata->int_data);
  1186.         break;
  1187.  
  1188.       case PELEM_BACK_INT_REFL_EQN:
  1189.         pset_back_refl_eqn(elcont->eldata->int_data);
  1190.         break;
  1191.  
  1192.       case PELEM_SURF_APPROX_CRIT:
  1193.         pset_surf_approx(elcont->eldata->surf_approx.type,
  1194.           elcont->eldata->surf_approx.u_val, 
  1195.           elcont->eldata->surf_approx.v_val);
  1196.         break;
  1197.  
  1198.       case PELEM_PARA_SURF_CHARACS:
  1199.         pset_para_surf_characs(elcont->eldata->para_surf_characs.type,
  1200.           &elcont->eldata->para_surf_characs.data);
  1201.         break;
  1202.  
  1203.       case PELEM_FACE_DISTING_MODE:
  1204.         pset_face_disting_mode(elcont->eldata->disting_mode);
  1205.         break;
  1206.  
  1207.       case PELEM_FACE_CULL_MODE:
  1208.         pset_face_cull_mode(elcont->eldata->cull_mode);
  1209.         break;
  1210.  
  1211.       case PELEM_LIGHT_SRC_STATE:
  1212.         pset_light_src_state(&elcont->eldata->lss.activation,
  1213.                              &elcont->eldata->lss.deactivation);
  1214.         break;
  1215.  
  1216.       case PELEM_DCUE_IND:
  1217.         pset_dcue_ind(elcont->eldata->int_data);
  1218.         break;
  1219.  
  1220.       case PELEM_COLR_MAP_IND:
  1221.         pset_colr_map_ind(elcont->eldata->int_data);
  1222.         break;
  1223.  
  1224.       case PELEM_RENDERING_COLR_MODEL:
  1225.         pset_rendering_colr_model(elcont->eldata->int_data);
  1226.         break;
  1227.  
  1228. #endif
  1229.  
  1230.       default:
  1231.         /* ptk_error(unknown element) */
  1232.         break;
  1233.   }
  1234. }  /* ptk_executeelem */
  1235.  
  1236. /*--------------------------------------------------------------------------*/
  1237.  
  1238. /*function:external*/
  1239. extern void ptk_copyelem(C(Pint) structid, C(Pint) elemid)
  1240. PreANSI(Pint structid)
  1241. PreANSI(Pint elemid)
  1242. /*
  1243. ** \parambegin
  1244. ** \param{Pint}{structid}{structure identifier}{IN}
  1245. ** \param{Pint}{elemid}{element number}{IN}
  1246. ** \paramend
  1247. ** \blurb{This function copies the element at position \pardesc{elemid}
  1248. ** in structuyre \pardesc{structid}, into the currently
  1249. ** open structure.}
  1250. */
  1251. {
  1252.   Pint error, actualsize;
  1253.   Pstore store;
  1254.   ptkselcontent elcont;
  1255.  
  1256.   /* find out type and contents of element */
  1257. #ifndef HP
  1258.   pcreate_store(&error, &store);
  1259.   ptk_inqelemtypesizecontent(structid, elemid, store, &error, &elcont);
  1260. #endif
  1261. #ifdef HP
  1262.   if (!hpstorecreated)
  1263.   {
  1264.     pcreate_store(&error, &hpstore);
  1265.     hpstorecreated = TRUE;
  1266.   }
  1267.   ptk_inqelemtypesizecontent(structid, elemid, hpstore, &error, &elcont);
  1268. #endif
  1269.   if (error == 0) 
  1270.     ptk_executeelem(&elcont);
  1271.   ptk_delstore(store);
  1272. }  /* ptk_copyelem */
  1273.  
  1274. /*--------------------------------------------------------------------------*/
  1275.  
  1276. /*function:external*/
  1277. extern void ptk_getprimitivetypename(C(Pattrs) attr, C(Pint) size, 
  1278.                                      C(char *) attrstr, C(Pint *) totalsize)
  1279. PreANSI(Pattrs attr)
  1280. PreANSI(Pint size)
  1281. PreANSI(char *attrstr)
  1282. PreANSI(Pint *totalsize)
  1283. /*
  1284. ** \parambegin
  1285. ** \param{Pattrs}{attr}{primitive type}{IN}
  1286. ** \param{Pint}{size}{size of buffer allocated by application}{IN}
  1287. ** \param{char *}{attrstr}{string giving primitive type}{OUT}
  1288. ** \param{Pint *}{totalsize}{length of string}{OUT}
  1289. ** \paramend
  1290. ** \blurb{The function converts the  primitive type \pardesc{attr}
  1291. **  to its corresponding character string, which is returned in
  1292. ** \pardesc{artrstr}. For example, P\_POLYLINE would give "polyline".}
  1293. */
  1294. {
  1295.   *totalsize = strlen(attrlist[(Pint)attr]) + 1;
  1296.    if (*totalsize <= size)
  1297.      strncpy(attrstr, attrlist[(Pint)attr], *totalsize);  
  1298. }  /* ptk_getprimitivetypename */
  1299.  
  1300. /*--------------------------------------------------------------------------*/
  1301.  
  1302. /*function:external*/
  1303. extern void ptk_copyelemrange(C(Pint) stid, C(Pint) elem1, C(Pint) elem2) 
  1304. PreANSI(Pint stid)
  1305. PreANSI(Pint elem1)
  1306. PreANSI(Pint elem2)
  1307. /*
  1308. ** \parambegin
  1309. ** \param{Pint}{stid}{structure identifier}{IN}
  1310. ** \param{Pint}{elem1}{element pointer}{IN}
  1311. ** \param{Pint}{elem2}{element pointer}{IN}
  1312. ** \paramend
  1313. ** \blurb{This function copies the  element range \pardesc{elem1} to \pardesc{elem2}
  1314. ** in structure \pardesc{stid} into the currently open structure.}
  1315. */
  1316. {
  1317.   Pint i, err, openstid, elemptr, emin, emax;
  1318.   Popen_struct_status status;
  1319.   ptkboolean backwards;
  1320.  
  1321.   pinq_open_struct(&err, &status, &openstid);
  1322.   if (status == PSTRUCT_OPEN)
  1323.   {
  1324.     emin = PTKMIN(elem1, elem2);
  1325.     emax = PTKMAX(elem1, elem2);
  1326.     pinq_elem_ptr(&err, &elemptr);
  1327.     if ((openstid == stid) && (elemptr < emin))
  1328.     {
  1329.       for (i = emin; i <= emax; i++)
  1330.         ptk_copyelem(stid, (i * 2) - emin);
  1331.     }
  1332.     else
  1333.     for (i = emin; i <= emax; i++)
  1334.       ptk_copyelem(stid, i);
  1335.   }
  1336. }  /* ptk_copyelemrange */
  1337.  
  1338. /*--------------------------------------------------------------------------*/
  1339.  
  1340. /*function:external*/
  1341. extern ptkboolean ptk_removestruct(C(Pint) stid)
  1342. PreANSI(Pint stid)
  1343. /*
  1344. ** \parambegin
  1345. ** \param{Pint}{stid}{structure identifier}{IN}
  1346. ** \paramend
  1347. ** \blurb{This function deletes structure \pardesc{stid}, if it already exists,
  1348. ** returning TRUE if the structure was deleted, otherwise FALSE.}
  1349. */
  1350. {
  1351.   if (ptk_structexists(stid)) 
  1352.   {
  1353.     pdel_struct(stid);
  1354.     return TRUE;
  1355.   } 
  1356.   else
  1357.     return FALSE;
  1358. }  /* ptk_removestruct */
  1359.  
  1360. /*--------------------------------------------------------------------------*/
  1361.  
  1362. static ptkboolean inelemlist(C(Pelem_type *) elemlist, C(Pint) lenlist,
  1363.                           C(Pelem_type) elem, C(Pint *) lstnum)
  1364. PreANSI(Pelem_type *elemlist)
  1365. PreANSI(Pint lenlist)
  1366. PreANSI(Pelem_type elem)
  1367. PreANSI(Pint *lstnum)
  1368. /*
  1369. ** \parambegin
  1370. ** \param{}{elemlist}{list of element types}{IN}
  1371. ** \param{}{lenlist}{length of element type list}{IN}
  1372. ** \param{}{elem}{element type to search for}{IN}
  1373. ** \param{}{lstnum}{index of found item in list}{OUT}
  1374. ** \paramend
  1375. ** \blurb{This function searches \pardesc{elemlist} for an
  1376. **  element of type \pardesc{elem}, returning
  1377. **  TRUE if the element type is found in list, otherwise FALSE.}
  1378. */
  1379. {
  1380.   Pint i;
  1381.   ptkboolean found;
  1382.  
  1383.   i = 0;
  1384.   found = FALSE;
  1385.   while ((found == FALSE) && (i < lenlist))
  1386.   {
  1387.     if (elemlist[i] == elem)
  1388.     {
  1389.       found = TRUE;
  1390.       *lstnum = i;
  1391.     }
  1392.     i++;
  1393.   }
  1394.   return found;
  1395. }
  1396.  
  1397. /*--------------------------------------------------------------------------*/
  1398.  
  1399. /*function:external*/
  1400. extern void ptk_findelemtype(C(Pelem_type *) eltypelst, C(Pint) lenlst,
  1401.                 C(Psearch_dir) srchdir, C(Psearch_status *) srchstat, 
  1402.                 C(Pint *) elptr, C(Pint *) lstnum)
  1403. PreANSI(Pelem_type *eltypelst)
  1404. PreANSI(Pint lenlst)
  1405. PreANSI(Psearch_dir srchdir)
  1406. PreANSI(Psearch_status *srchstat)
  1407. PreANSI(Pint *elptr)
  1408. PreANSI(Pint *lstnum)
  1409. /*
  1410. ** \parambegin
  1411. ** \param{Pelem\_type *}{eltypelst}{list of element types}{IN}
  1412. ** \param{Pint}{lenlst}{length of element type list}{IN}
  1413. ** \param{Psearch\_dir}{srchdir}{search direction, forwards or backwards}{IN}
  1414. ** \param{Psearch\_status *}{srchstat}{search success or failure}{OUT}
  1415. ** \param{Pint *}{elptr}{found element pointer}{OUT}
  1416. ** \param{Pint *}{lstnum}{index of found item in list}{OUT}
  1417. ** \paramend
  1418. ** \blurb{This function searches
  1419. **  the currently open
  1420. ** structure, starting at the current element pointer and proceeding in
  1421. **  direction \pardesc{srchdir}, for the first element whose type
  1422. ** matches any of those given in \pardesc{contentlst}.}
  1423. */
  1424. {
  1425.   Pint structid, elemptr;
  1426.   Pint err;
  1427.   Popen_struct_status status;
  1428.   Pint maxelems;
  1429.   Pelem_type etype;
  1430.   size_t esize;
  1431.  
  1432.   pinq_open_struct(&err, &status, &structid);   
  1433.   if (status == PSTRUCT_NONE)
  1434.   {
  1435.     /* ptk_error("no open structure"); */
  1436.   }
  1437.   else
  1438.   {
  1439.     pinq_elem_ptr(&err, &elemptr);
  1440.     maxelems = ptk_elemcount(structid);
  1441.     *srchstat = PSEARCH_STATUS_FAILURE;
  1442.     while ((*srchstat == PSEARCH_STATUS_FAILURE) && (elemptr >= 0)
  1443.            && (elemptr <= maxelems))
  1444.     {
  1445.       pset_elem_ptr(elemptr);      
  1446.       pinq_cur_elem_type_size(&err, &etype, &esize);
  1447.       if (inelemlist(eltypelst, lenlst, etype, lstnum))
  1448.       {
  1449.         *srchstat = PSEARCH_STATUS_SUCCESS;
  1450.         *elptr = elemptr;
  1451.       }
  1452.       else
  1453.       {
  1454.         if (srchdir == PDIR_FORWARD)
  1455.           elemptr++;
  1456.         else
  1457.           elemptr--;
  1458.       }
  1459.     }
  1460.   }
  1461. }  /* ptk_findelemtype */
  1462.  
  1463. /*--------------------------------------------------------------------------*/
  1464.  
  1465. /*function:external*/
  1466. extern ptkboolean ptk_findnextpickid(C(Pint) stid, C(Psearch_dir) srchdir,
  1467.                                 C(Pint *) eltptr, C(Pint *) pickid)
  1468. PreANSI(Pint stid)
  1469. PreANSI(Psearch_dir srchdir)
  1470. PreANSI(Pint *eltptr)
  1471. PreANSI(Pint *pickid)
  1472. /*
  1473. ** \parambegin
  1474. ** \param{Pint}{stid}{structure identifier}{IN}
  1475. ** \param{Psearch\_dir}{srchdir}{search direction}{IN}
  1476. ** \param{Pint *}{eltptr}{element pointer of pick identifier}{OUT}
  1477. ** \param{Pint *}{pickid}{pick identifier value}{OUT}
  1478. ** \paramend
  1479. ** \blurb{This function searches structure \pardesc{stid}, starting
  1480. ** at element \pardesc{elptr} and proceeding in direction \pardesc{srchdir},
  1481. ** looking for a pick identifier structure element. The function
  1482. ** returns TRUE if a pick identifier was found, otherwise FALSE.}
  1483. */
  1484. {
  1485.   Pint openst;
  1486.   Popen_struct_status openstat;
  1487.   Pint err, oldp;
  1488.   ptkboolean result;
  1489.   Pint stat;
  1490.   Psearch_status searchstat;
  1491.   Pelem_type eltype;
  1492.   Pint lenlist, lstnum;
  1493.  
  1494.   ptk_openstruct(stid);
  1495.   pset_elem_ptr(*eltptr);
  1496.   eltype = PELEM_PICK_ID;
  1497.   lenlist = 1;
  1498.   ptk_findelemtype(&eltype, lenlist, srchdir, &searchstat, eltptr, &lstnum);
  1499.   ptk_closestruct();
  1500.   if (searchstat == PSEARCH_STATUS_SUCCESS)
  1501.   {
  1502.     ptk_getpickid(stid, *eltptr, pickid);
  1503.     result = TRUE;
  1504.   }
  1505.   else
  1506.     result = FALSE;
  1507.   return result;
  1508. }  /* ptk_findnextpickid */
  1509.  
  1510. /*------------------------------------------------------------------------*/
  1511.  
  1512. /*function:external*/
  1513. extern ptkboolean ptk_findlabel(C(Pint) label, C(Pint *) elemptr)
  1514. PreANSI(Pint label)
  1515. PreANSI(Pint *elemptr)
  1516. /*
  1517. ** \parambegin
  1518. ** \param{Pint}{label}{label value}{IN}
  1519. ** \param{Pint *}{elemptr}{element pointer of label element}{IN/OUT}
  1520. ** \paramend
  1521. ** \blurb{This function searches forwards through the currently open
  1522. ** structure from the current editing position
  1523. ** looking for a label structure element. The function
  1524. ** returns TRUE if {\tt label} was found, otherwise FALSE.}
  1525. */
  1526. {
  1527.   ptkboolean found;
  1528.   Pint err, eptr;
  1529.   Pstore store;
  1530.   ptkselcontent elcont;
  1531.  
  1532.   found = FALSE;
  1533.   pset_elem_ptr_label(label);
  1534.   pinq_elem_ptr(&err, &eptr);
  1535.   pcreate_store(&err, &store);
  1536.   ptk_inqcurelemtypesizecontent(store, &err, &elcont);
  1537.   if (elcont.eltype == PELEM_LABEL)
  1538.     if (elcont.eldata->int_data = label)
  1539.     {
  1540.       found = TRUE;
  1541.       *elemptr = eptr;
  1542.     }
  1543.   ptk_delstore(store);
  1544.   return found;
  1545. }  /* ptk_findlabel */
  1546.  
  1547. /*------------------------------------------------------------------------*/
  1548.  
  1549. /*function:external*/
  1550. extern void ptk_delelemtype(C(Pint) stid, C(Pint) lenlst, 
  1551.                             C(Pelem_type *) eltypelst)
  1552. PreANSI(Pint stid)
  1553. PreANSI(Pint lenlst)
  1554. PreANSI(Pelem_type *eltypelst)
  1555. /*
  1556. ** \parambegin
  1557. ** \param{Pint}{stid}{structure identifier}{IN}
  1558. ** \param{Pint}{lenlst}{length of element type list}{IN}
  1559. ** \param{Pelem\_type *}{eltypelst}{list of element types to delete}{IN}
  1560. ** \paramend
  1561. ** \blurb{This function deletes every element in structure \pardesc{stid}, whose
  1562. ** type matches one of the types  in \pardesc{eltypelst}}.
  1563. */
  1564. {
  1565.   ptkboolean finished;
  1566.   Psearch_status srchstatus;
  1567.   Pint elptr, lstnum;
  1568.  
  1569.   finished = FALSE;
  1570.   elptr = 0;
  1571.   ptk_openstruct(stid);
  1572.   pset_elem_ptr(elptr);
  1573.   while (!finished)
  1574.   {
  1575.     ptk_findelemtype(eltypelst, lenlst, PDIR_FORWARD, &srchstatus, 
  1576.                      &elptr, &lstnum);
  1577.     if (srchstatus == PSEARCH_STATUS_SUCCESS)
  1578.     {
  1579.       pset_elem_ptr(elptr);      
  1580.       pdel_elem();
  1581.     }
  1582.     else
  1583.       finished = TRUE;
  1584.   }
  1585.   ptk_closestruct();
  1586. }  /* ptk_delelemtype */
  1587.  
  1588. /*------------------------------------------------------------------------*/
  1589.  
  1590. /*function:external*/
  1591. extern void ptk_delelem(C(Pint) numelems)
  1592. PreANSI(Pint numelems)
  1593. /*
  1594. ** \parambegin
  1595. ** \param{Pint}{numelems}{number of elements to delete}{IN}
  1596. ** \paramend
  1597. ** \blurb{This function deletes the \pardesc{numelms} elements from the
  1598. ** open structure, starting at the element pointer. If \pardesc{numelems} is
  1599. **  0, all elements up to the end of
  1600. ** the structure are deleted.}
  1601. */
  1602. {
  1603.   Pint i, range, err, elptr, stid, maxelems;
  1604.   Popen_struct_status status;
  1605.  
  1606.   if (numelems == 0)
  1607.   {
  1608.     pinq_open_struct(&err, &status, &stid);
  1609.     pinq_elem_ptr(&err, &elptr);
  1610.     maxelems = ptk_elemcount(stid);
  1611.     range = maxelems - elptr;
  1612.   }
  1613.   else
  1614.     range = numelems;
  1615.   for (i = 0; i < range; i++)
  1616.   {
  1617.     pdel_elem();
  1618.     poffset_elem_ptr(1);
  1619.   }
  1620.   poffset_elem_ptr(-1);
  1621. }  /* ptk_delelem */
  1622.  
  1623. /*------------------------------------------------------------------------*/
  1624.  
  1625. /*function:external*/
  1626. extern Pint ptk_countchildren(C(Pint) stid)
  1627. PreANSI(Pint stid)
  1628. /*
  1629. ** \parambegin
  1630. ** \param{Pint}{stid}{structure identifier}{IN}
  1631. ** \paramend
  1632. ** \blurb{The function returns the number of structures executed by structure
  1633. ** \pardesc{stid}.
  1634. ** This is the number of direct execute elements in the structure.}
  1635. */
  1636. {
  1637.   Pint e, c, err, foundel, numels;
  1638.   Psearch_status status;
  1639.   Pelem_type exectype;
  1640.   Pelem_type_list includelst, excludelst;
  1641.   Popen_struct_status openstatus;
  1642.  
  1643.   e = 0;
  1644.   c = 0;
  1645.   numels = ptk_elemcount(stid);
  1646.   includelst.num_elem_types = 1;
  1647.   exectype = PELEM_EXEC_STRUCT;
  1648.   includelst.elem_types = &exectype;
  1649.   excludelst.num_elem_types = 0;
  1650.   excludelst.elem_types = NULL;
  1651.   do 
  1652.   {
  1653.     pelem_search(stid, e, PDIR_FORWARD, &includelst, &excludelst, &err, 
  1654.                  &status, &foundel);
  1655.     e = foundel + 1;
  1656.     if (status == PSEARCH_STATUS_SUCCESS) 
  1657.       c++;
  1658.   } while ((status != PSEARCH_STATUS_FAILURE) && (e <= numels));
  1659.   return c;
  1660. }  /* ptk_countchildren */
  1661.  
  1662. /*--------------------------------------------------------------------------*/
  1663.  
  1664. /*function:external*/
  1665. extern Pint ptk_countuniqchildren(C(Pint) stid)
  1666. PreANSI(Pint stid)
  1667. /*
  1668. ** \parambegin
  1669. ** \param{Pint}{stid}{structure identifier}{IN}
  1670. ** \paramend
  1671. ** \blurb{This function returns the number of unique children of  structure
  1672. ** \pardesc{stid}. Thus, if a structure executed structures A, B and C, it would
  1673. ** have 3 unique children, regardless of how many times each of A, B and C were
  1674. ** executed.}
  1675. */
  1676. {
  1677.   Pint e, err, foundel, numels, childstid[255];
  1678.   Psearch_status status;
  1679.   Pelem_type exectype;
  1680.   Pelem_type_list includelst, excludelst;
  1681.   Popen_struct_status openstatus;
  1682.   Pint_list children;
  1683.   Pstore store;
  1684.   ptkselcontent elcont;
  1685.  
  1686.   e = 0;
  1687.   children.num_ints = 0;
  1688.   children.ints = childstid;
  1689.   numels = ptk_elemcount(stid);
  1690.   includelst.num_elem_types = 1;
  1691.   exectype = PELEM_EXEC_STRUCT;
  1692.   includelst.elem_types = &exectype;
  1693.   excludelst.num_elem_types = 0;
  1694.   excludelst.elem_types = NULL;
  1695.   do 
  1696.   {
  1697.     pelem_search(stid, e, PDIR_FORWARD, &includelst, &excludelst, &err, 
  1698.                  &status, &foundel);
  1699.     e = foundel + 1;
  1700.     if (status == PSEARCH_STATUS_SUCCESS) 
  1701.     {
  1702.       pcreate_store(&err, &store);
  1703.       ptk_inqelemtypesizecontent(stid, foundel, store, &err, &elcont);
  1704.       if (inintlst(elcont.eldata->int_data, &children) == -1)
  1705.         children.ints[children.num_ints++] = elcont.eldata->int_data;
  1706.       ptk_delstore(store);
  1707.     }
  1708.   } while ((status != PSEARCH_STATUS_FAILURE) && (e <= numels));
  1709.   return children.num_ints;
  1710. }  /* ptk_countuniqchildren */
  1711.  
  1712. /*--------------------------------------------------------------------------*/
  1713.  
  1714. /*function:external*/
  1715. extern void ptk_inqstructnetids(C(Pint) root, C(Pint) size, 
  1716.                                 C(Pint_list *) stids, C(Pint *) totalsize)
  1717. PreANSI(Pint root)
  1718. PreANSI(Pint size)
  1719. PreANSI(Pint_list *stids)
  1720. PreANSI(Pint *totalsize)
  1721. /*
  1722. ** \parambegin
  1723. ** \param{Pint}{root}{structure network identifer}{IN}
  1724. ** \param{Pint}{size}{number of integers allocated in integer list}{IN}
  1725. ** \param{Pint\_list *}{stids}{list of structure identifiers}{OUT}
  1726. ** \param{Pint *}{totalsize}{actual number of integers in integer list}{OUT}
  1727. ** \paramend
  1728. ** \blurb{This function returns a
  1729. **  list of structure identifiers in the structure network whose 
  1730. ** root is \pardesc{root}.} 
  1731. */
  1732. {
  1733.   Pint_list stidlist;
  1734.   Pint ids[500];
  1735.   Pint err, i, j;
  1736.   Ppath_order order;
  1737.   Pstore store;
  1738.   Pelem_ref_list_list *paths;
  1739.  
  1740.   stidlist.num_ints = 0;
  1741.   stidlist.ints = ids;
  1742.   pcreate_store(&err, &store);
  1743.   pinq_paths_descs(root, PORDER_TOP_FIRST, 0, store, &err, &paths);
  1744.   for (i = 0; i < paths->num_elem_ref_lists; i++)
  1745.   {
  1746.     for (j = 0; j < paths->elem_ref_lists[i].num_elem_refs; j++)
  1747.     {
  1748.       if (inintlst(paths->elem_ref_lists[i].elem_refs[j].struct_id, 
  1749.           &stidlist) == -1)
  1750.         stidlist.ints[stidlist.num_ints++] = 
  1751.           paths->elem_ref_lists[i].elem_refs[j].struct_id;
  1752.     }
  1753.   }
  1754.   ptk_delstore(store);
  1755.   if (ptk_structexists(root) && (stidlist.num_ints == 0))
  1756.     stidlist.ints[stidlist.num_ints++] = root;
  1757.   stids->num_ints = *totalsize = stidlist.num_ints;
  1758.   if (size >= stidlist.num_ints)
  1759.   {
  1760.     for (i = 0; i < stidlist.num_ints; i++)
  1761.       stids->ints[i] = stidlist.ints[i];
  1762.   }
  1763. }  /* ptk_inqstructnetids */
  1764.  
  1765. /*--------------------------------------------------------------------------*/
  1766.                                
  1767. /*function:external*/
  1768. extern void ptk_structsummary(C(FILE *) fileptr)
  1769. PreANSI(FILE *fileptr)
  1770. /*
  1771. ** \parambegin
  1772. ** \param{FILE *}{fileptr}{file pointer}{IN}
  1773. ** \paramend
  1774. ** \blurb{This function outputs a summary of all the structures in the CSS to
  1775. ** file \pardesc{fileptr}, which should be an open writeable file.
  1776. ** The structure identifier of each structure is printed, together 
  1777. ** with its hashed string name, if it has one. The format 
  1778. ** of the list is: {\tt \\
  1779. ** \ \ \ \ \ List of structures in the CSS\\
  1780. ** \ \ \ \ \ -----------------------------\\
  1781. ** \ \\
  1782. ** \ \ \ \ \ structure 1 "helicopter"\\
  1783. ** \ \ \ \ \ structure 45 \\
  1784. ** \ \ \ \ \ structure 51 "helicopter"\\
  1785. ** \ \ \ \ \ etc. }
  1786. ** .}
  1787. */
  1788. {
  1789.   Pint length, totallength;
  1790.   Pint_list stlist;
  1791.   Pint *stids;
  1792.   Pint error, stringlen;
  1793.   char str[255];
  1794.   Pint i;
  1795.   ptkboolean dostring;
  1796.  
  1797.   length = 0;
  1798.   pinq_struct_ids(length, 0, &error, &stlist, &totallength);
  1799.   length = totallength;
  1800.   stids = (Pint *)calloc(length, sizeof(Pint));
  1801.   stlist.ints = stids;
  1802.   pinq_struct_ids(length, 0, &error, &stlist, &totallength);
  1803.   if (error != 0) 
  1804.   {
  1805.     /* ptk_error(error in ptk_structsummary) */
  1806.     return;
  1807.   }
  1808.   dostring = ptk_hashtableused("structureid"); 
  1809.   fprintf(fileptr, "List of structures in the CSS\n");
  1810.   fprintf(fileptr, "-----------------------------\n");
  1811.   for (i = 0; i < stlist.num_ints; i++) 
  1812.   {
  1813.     fprintf(fileptr, "structure %d", stlist.ints[i]);
  1814.  
  1815.     /* get corresponding string for structure id from hashtable */
  1816.     if (dostring)
  1817.     {
  1818.       ptk_inttostring("structureid", stlist.ints[i], 255, str, 
  1819.                       &totallength);
  1820.  
  1821.       /* print string, if there is one */
  1822.       if (totallength == 0)
  1823.         fprintf(fileptr, "\n");
  1824.       else 
  1825.       {
  1826.         fprintf(fileptr, " \"%s\"\n", str);
  1827.       }
  1828.     }
  1829.     else
  1830.       fprintf(fileptr, "\n");
  1831.   }
  1832. }  /* ptk_structsummary */
  1833.  
  1834. /*--------------------------------------------------------------------------*/
  1835. /*--------------------- Attribute Functions --------------------------------*/
  1836.  
  1837. /*function:external*/
  1838. extern void ptk_setattrasf(C(Pint) numattrs, C(Paspect *) attrs, C(Pasf) asf)
  1839. PreANSI(Pint numattrs)
  1840. PreANSI(Paspect *attrs)
  1841. PreANSI(Pasf asf)
  1842. /*
  1843. ** \parambegin
  1844. ** \param{Pint}{numattrs}{length of attribute list}{IN}
  1845. ** \param{Paspect *}{attrs}{attribute list}{IN}
  1846. ** \param{Pasf}{asf}{aspect source flag}{IN}
  1847. ** \paramend
  1848. ** \blurb{This function inserts a structure element into
  1849. ** the open structure to set the aspect source flags for each of the
  1850. ** \pardesc{numattrs} attributes in the
  1851. **  list \pardesc{attrs}, according to \pardesc{asf}.}
  1852. */
  1853. {
  1854.   Pint i;
  1855.  
  1856.   for (i = 0; i < numattrs; i++)
  1857.     pset_indiv_asf(attrs[i], asf);
  1858. }  /* ptk_setattrasf */
  1859.  
  1860. /*--------------------------------------------------------------------------*/
  1861.  
  1862. /*function:external*/
  1863. extern void ptk_setallattrasf(C(Pasf) asf)
  1864. PreANSI(Pasf asf)
  1865. /*
  1866. ** \parambegin
  1867. ** \param{Pasf}{asf}{aspect source flag}{IN}
  1868. ** \paramend
  1869. ** \blurb{This function inserts a structure element into
  1870. ** the open structure to set the aspect source flags for all primitive 
  1871. ** attributes, according to \pardesc{asf}.}
  1872. */
  1873. {
  1874.   /* PHIGS PLUS bits */
  1875. #ifdef SUN
  1876.   static Pint numattr = 30;
  1877.   static Paspect attrlist[] = {PASPECT_LINETYPE, PASPECT_LINEWIDTH,
  1878.   PASPECT_LINE_COLR_IND, PASPECT_MARKER_TYPE, PASPECT_MARKER_SIZE,
  1879.   PASPECT_MARKER_COLR_IND, PASPECT_TEXT_FONT, PASPECT_TEXT_PREC,
  1880.   PASPECT_CHAR_EXPAN, PASPECT_CHAR_SPACE, PASPECT_TEXT_COLR_IND,
  1881.   PASPECT_INT_STYLE, PASPECT_INT_STYLE_IND, PASPECT_INT_COLR_IND,
  1882.   PASPECT_EDGE_FLAG, PASPECT_EDGETYPE, PASPECT_EDGEWIDTH, 
  1883.   PASPECT_EDGE_COLR_IND, 
  1884.   PASPECT_LINE_SHAD_METH, PASPECT_INT_SHAD_METH,
  1885.   PASPECT_REFL_PROPS, PASPECT_INT_REFL_EQN,
  1886.   PASPECT_BACK_INT_STYLE, PASPECT_BACK_INT_STYLE_IND,
  1887.   PASPECT_BACK_INT_COLR, PASPECT_BACK_INT_SHAD_METH,
  1888.   PASPECT_BACK_REFL_PROPS, PASPECT_BACK_INT_REFL_EQN,
  1889.   PASPECT_CURVE_APPROX_CRIT, PASPECT_SURF_APPROX_CRIT};
  1890. #else
  1891.   static Pint numattr = 18;
  1892.   static Paspect attrlist[] = {PASPECT_LINETYPE, PASPECT_LINEWIDTH,
  1893.   PASPECT_LINE_COLR_IND, PASPECT_MARKER_TYPE, PASPECT_MARKER_SIZE,
  1894.   PASPECT_MARKER_COLR_IND, PASPECT_TEXT_FONT, PASPECT_TEXT_PREC,
  1895.   PASPECT_CHAR_EXPAN, PASPECT_CHAR_SPACE, PASPECT_TEXT_COLR_IND,
  1896.   PASPECT_INT_STYLE, PASPECT_INT_STYLE_IND, PASPECT_INT_COLR_IND,
  1897.   PASPECT_EDGE_FLAG, PASPECT_EDGETYPE, PASPECT_EDGEWIDTH, 
  1898.   PASPECT_EDGE_COLR_IND};
  1899. #endif
  1900.   ptk_setattrasf(numattr, attrlist, asf);
  1901. }  /* ptk_setallattrasf */
  1902.  
  1903. /*--------------------------------------------------------------------------*/
  1904.  
  1905. /*function:external*/
  1906. extern Pedge_bundle ptk_setedgebundlerec(C(Pedge_flag) eflag, C(Pint) etype,
  1907.                     C(Pfloat) escale, C(Pint) ecolour)
  1908. PreANSI(Pedge_flag eflag)
  1909. PreANSI(Pint etype)
  1910. PreANSI(Pfloat escale)
  1911. PreANSI(Pint ecolour)
  1912. /*
  1913. ** \parambegin
  1914. ** \param{Pedge\_flag}{eflag}{edge on or off}{IN}
  1915. ** \param{Pint}{etype}{edge type (solid, dotted,..)}{IN}
  1916. ** \param{Pfloat}{escale}{edge width scale factor}{IN}
  1917. ** \param{Pint}{ecolour}{edge colour index}{IN}
  1918. ** \paramend
  1919. ** \blurb{This function sets creates and
  1920. ** returns an edge bundle attribute record whose fields are set as specified.}
  1921. */
  1922. {
  1923.   Pedge_bundle edgerec;
  1924.  
  1925.   edgerec.flag = eflag;
  1926.   edgerec.type = etype;
  1927.   edgerec.width = escale;
  1928.   edgerec.colr_ind = ecolour;
  1929.   return edgerec;
  1930. }  /* ptk_setedgebundlerec */
  1931.  
  1932. /*--------------------------------------------------------------------------*/
  1933.  
  1934. /*function:external*/
  1935. extern Pint_bundle ptk_setinteriorbundlerec(C(Pint_style) istyle,
  1936.                      C(Pint) index, C(Pint) icolour)
  1937. PreANSI(Pint_style istyle)
  1938. PreANSI(Pint index)
  1939. PreANSI(Pint icolour)
  1940. /*
  1941. ** \parambegin
  1942. ** \param{Pint\_style}{istyle}{interior style (solid, hollow,..)}{IN}
  1943. ** \param{Pint}{index}{interior style index for pattern or hatch}{IN}
  1944. ** \param{Pint}{icolour}{interior colour index}{IN}
  1945. ** \paramend
  1946. ** \blurb{This function sets creates and
  1947. ** returns an interior bundle attribute record whose fields are set as specified.}
  1948. */
  1949. {
  1950.   Pint_bundle inrec;
  1951.  
  1952.   inrec.style = istyle;
  1953.   inrec.style_ind = index;
  1954.   inrec.colr_ind = icolour;
  1955.   return inrec;
  1956. }  /* ptk_setinteriorbundlerec */
  1957.  
  1958. /*--------------------------------------------------------------------------*/
  1959.  
  1960. /*function:external*/
  1961. extern Pline_bundle ptk_setpolylinebundlerec(C(Pint) ltype, C(Pfloat) lwidth,
  1962.                   C(Pint) lcolour)
  1963. PreANSI(Pint ltype)
  1964. PreANSI(Pfloat lwidth)
  1965. PreANSI(Pint lcolour)
  1966. /*
  1967. ** \parambegin
  1968. ** \param{Pint}{ltype}{line type (solid, dotted,..)}{IN}
  1969. ** \param{Pfloat}{lwidth}{line width scale factor}{IN}
  1970. ** \param{Pint}{lcolour}{line colour index}{IN}
  1971. ** \paramend
  1972. ** \blurb{This function sets creates and
  1973. ** returns a polyline bundle attribute record whose fields are set as specified.}
  1974. */
  1975. {
  1976.   Pline_bundle lnrec;
  1977.  
  1978.   lnrec.type = ltype;
  1979.   lnrec.width = lwidth;
  1980.   lnrec.colr_ind = lcolour;
  1981.   return lnrec;
  1982. }  /* ptk_setpolylinebundlerec */
  1983.  
  1984. /*--------------------------------------------------------------------------*/
  1985.  
  1986. /*function:external*/
  1987. extern Pmarker_bundle ptk_setpolymarkerbundlerec(C(Pint) mtype, C(Pfloat) msize,
  1988.                   C(Pint) mcolour)
  1989. PreANSI(Pint mtype)
  1990. PreANSI(Pfloat msize)
  1991. PreANSI(Pint mcolour)
  1992. /*
  1993. ** \parambegin
  1994. ** \param{Pint}{mtype}{marker type (dot, circle,..)}{IN}
  1995. ** \param{Pfloat}{msize}{marker size scale factor}{IN}
  1996. ** \param{Pint}{mcolour}{marker colour index}{IN}
  1997. ** \paramend
  1998. ** \blurb{This function sets creates and
  1999. ** returns an polymarker bundle attribute record whose fields are set as specified.}
  2000. */
  2001. {
  2002.   Pmarker_bundle mkrec;
  2003.  
  2004.   mkrec.type = mtype;
  2005.   mkrec.size = msize;
  2006.   mkrec.colr_ind = mcolour;
  2007.   return mkrec;
  2008. }  /* ptk_setpolymarkerbundlerec */
  2009.  
  2010. /*--------------------------------------------------------------------------*/
  2011.  
  2012. /*function:external*/
  2013. extern Ptext_bundle ptk_settextbundlerec(C(Pint) tfont, C(Ptext_prec) tprec,
  2014.                   C(Pfloat) texp, C(Pfloat) tspace, C(Pint) tcolour)
  2015. PreANSI(Pint tfont)
  2016. PreANSI(Ptext_prec tprec)
  2017. PreANSI(Pfloat texp)
  2018. PreANSI(Pfloat tspace)
  2019. PreANSI(Pint tcolour)
  2020. /*
  2021. ** \parambegin
  2022. ** \param{Pint}{tfont}{text font}{IN}
  2023. ** \param{Ptext\_prec}{tprec}{text precision}{IN}
  2024. ** \param{Pfloat}{texp}{character expansion factor}{IN}
  2025. ** \param{Pfloat}{tspace}{character spacing}{IN}
  2026. ** \param{Pint}{tcolour}{text colour index}{IN}
  2027. ** \paramend
  2028. ** \blurb{This function sets creates and
  2029. ** returns a text bundle attribute record whose fields are set as specified.}
  2030. */
  2031. {
  2032.   Ptext_bundle txrec;
  2033.  
  2034.   txrec.font = tfont;
  2035.   txrec.prec = tprec;
  2036.   txrec.char_expan = texp;
  2037.   txrec.char_space = tspace;
  2038.   txrec.colr_ind = tcolour;
  2039.   return txrec;
  2040. }  /* ptk_settextbundlerec */
  2041.  
  2042. /*--------------------------------------------------------------------------*/
  2043.  
  2044. /*function:external*/
  2045. extern void ptk_computecharsize(C(Pint) wsid, C(char *) str, C(Ppoint *) box,
  2046.                                 C(Pint) font, C(Pfloat *) charht, 
  2047.                                 C(Pfloat *) charexp)
  2048. PreANSI(Pint wsid)
  2049. PreANSI(char *str)
  2050. PreANSI(Ppoint *box)
  2051. PreANSI(Pint font)
  2052. PreANSI(Pfloat *charht)
  2053. PreANSI(Pfloat *charexp)
  2054. /*
  2055. ** \parambegin
  2056. ** \param{Pint}{wsid}{workstation identifier}{IN}
  2057. ** \param{char *}{str}{string}{IN}
  2058. ** \param{Ppoint *}{box}{width and height of box}{IN}
  2059. ** \param{Pint}{font}{text font}{IN}
  2060. ** \param{Pfloat *}{charht}{character height}{OUT}
  2061. ** \param{Pfloat *}{charexp}{character expansion}{OUT}
  2062. ** \paramend
  2063. ** \blurb{This function computes the character height and expansion for 
  2064. **  string \pardesc{str}, using font \pardesc{font}, 
  2065. ** in order for it to fit into the rectangle specifed by \pardesc{box}.}
  2066. */
  2067. {
  2068.   Pint err, totsize, wstype;
  2069.   Pstore store;
  2070.   void *connid;
  2071.   Prect rect;
  2072.   Ppoint offset;
  2073.   Pfloat stringwidth, charheight;
  2074.  
  2075. #ifdef SUN
  2076.   pcreate_store(&err, &store);
  2077.   pinq_ws_conn_type(wsid, store, &err, &connid, &wstype);
  2078.   pinq_text_extent(wstype, font, 1.0, 0.0, 0.01, PPATH_RIGHT, 
  2079.     PHOR_NORM, PVERT_NORM, str, &err, &rect, &offset);
  2080.  
  2081.   charheight = rect.q.y - rect.p.y;
  2082.   *charht = 0.01 * (box->y/charheight);
  2083.  
  2084.   pinq_text_extent(wstype, font, 1.0, 0.0, *charht, PPATH_RIGHT, 
  2085.     PHOR_NORM, PVERT_NORM, str, &err, &rect, &offset);
  2086.   stringwidth = rect.q.x - rect.p.x;
  2087.   *charexp = 1.0 * (box->x/stringwidth);
  2088.   ptk_delstore(store);
  2089. #endif
  2090. #ifndef SUN
  2091.   /* do for HP and PEXSI */
  2092.   charheight = box->y;
  2093.   stringwidth = strlen(str) * charheight;
  2094.   *charht = charheight;
  2095.   *charexp = 1.0 * (box->x/stringwidth);
  2096. #endif
  2097. }  /* ptk_computecharsize */
  2098.  
  2099. /*--------------------------------------------------------------------------*/
  2100.  
  2101. /*function:external*/
  2102. extern void ptk_computecharheight(C(Pint) wsid, C(char *) str, 
  2103.                            C(Ppoint *) box, C(Pint) font, C(Pfloat *) charht) 
  2104. PreANSI(Pint wsid)
  2105. PreANSI(char *str)
  2106. PreANSI(Ppoint *box)
  2107. PreANSI(Pint font)
  2108. PreANSI(Pfloat *charht)
  2109. /*
  2110. ** \parambegin
  2111. ** \param{Pint}{wsid}{workstation identifier}{IN}
  2112. ** \param{char *}{str}{string}{IN}
  2113. ** \param{Ppoint *}{box}{width and height of box}{IN}
  2114. ** \param{Pint}{font}{text font}{IN}
  2115. ** \param{Pfloat *}{charht}{character height}{OUT}
  2116. ** \paramend
  2117. ** \blurb{This function computes the character height for 
  2118. **  string \pardesc{str}, using font \pardesc{font}, 
  2119. ** in order for it to fit into the rectangle specifed by \pardesc{box}.}
  2120. */
  2121. {
  2122.   Pint err, totsize, wstype;
  2123.   Pstore store;
  2124.   void *connid;
  2125.   Prect rect;
  2126.   Ppoint offset;
  2127.   Pfloat stringwidth, charheight, width, height;
  2128.  
  2129. #ifdef SUN
  2130.   pcreate_store(&err, &store);
  2131.   pinq_ws_conn_type(wsid, store, &err, &connid, &wstype);
  2132.   pinq_text_extent(wstype, font, 1.0, 0.0, 0.01, PPATH_RIGHT, 
  2133.     PHOR_NORM, PVERT_NORM, str, &err, &rect, &offset);
  2134.   ptk_delstore(store);
  2135.   charheight = rect.q.y - rect.p.y; 
  2136.   stringwidth = rect.q.x - rect.p.x;
  2137.   height = 0.01 * (box->y / charheight);
  2138.   width = stringwidth * (height / 0.01);
  2139.   if (width > box->x)
  2140.     height *= (box->x / width);
  2141.   *charht = height;
  2142. #endif
  2143. #ifndef SUN
  2144.   /* do for HP and PEXSI */
  2145.   /* assume mono-spaced font, font = 1, path = right */
  2146.   charheight = box->y; 
  2147.   stringwidth = strlen(str) * box->y;
  2148.   if (stringwidth > box->x)
  2149.     charheight *= (box->x / stringwidth);
  2150.   *charht = charheight;
  2151. #endif
  2152. }  /* ptk_computecharheight */
  2153.  
  2154. /*--------------------------------------------------------------------------*/
  2155. /*----------------------- Viewing Functions --------------------------------*/
  2156.  
  2157. /*function:external*/
  2158. extern void ptk_setstandardviewport(C(Plimit3 *) vlimits, C(Pview_rep3 *) rep)
  2159. PreANSI(Plimit3 *vlimits)
  2160. PreANSI(Pview_rep3 *rep)
  2161. /*
  2162. ** \parambegin
  2163. ** \param{Plimit3 *}{vlimits}{viewport bounding box}{IN}
  2164. ** \param{Pview\_rep3 *}{rep}{view representation}{OUT}
  2165. ** \paramend
  2166. ** \blurb{For a window of [0,1], this function creates in \pardesc{rep}
  2167. **  a view representation
  2168. **  for a viewport of 
  2169. ** \pardesc{vlimits}.}
  2170. */
  2171. {
  2172.   Pview_map3 viewmap;
  2173.   Pint err;
  2174.  
  2175.   viewmap.view_plane = 1.0;
  2176.   viewmap.proj_type = PTYPE_PARAL;
  2177.   viewmap.proj_ref_point = ptk_point3(0.5, 0.5, 2.0);
  2178.   viewmap.win = ptk_limit(0.0, 1.0, 0.0, 1.0);
  2179.   viewmap.back_plane = -1.0;
  2180.   viewmap.front_plane = 1.0;
  2181.   viewmap.proj_vp = *vlimits;
  2182.   peval_view_map_matrix3(&viewmap, &err, rep->map_matrix);
  2183.   ptk_unitmatrix3(rep->ori_matrix);
  2184.   rep->clip_limit = *vlimits;
  2185.   rep->xy_clip = PIND_CLIP;
  2186.   rep->front_clip = PIND_CLIP;
  2187.   rep->back_clip = PIND_CLIP;
  2188. }  /* ptk_setstandardviewport */
  2189.  
  2190. /*--------------------------------------------------------------------------*/
  2191. /*--------------------------- Post Functions -------------------------------*/
  2192.  
  2193. /*function:external*/
  2194. extern void ptk_poststruct(C(Pint) wsid, C(Pint) stid, C(Pfloat) priority)
  2195. PreANSI(Pint wsid)
  2196. PreANSI(Pint stid)
  2197. PreANSI(Pfloat priority)
  2198. /*
  2199. ** \parambegin
  2200. ** \param{Pint}{wsid}{workstation identifier}{IN}
  2201. ** \param{Pint}{stid}{structure identifier}{IN}
  2202. ** \param{Pfloat}{priority}{priority with which to post structure}{IN}
  2203. ** \paramend
  2204. ** \blurb{This function posts structure \pardesc{stid} to
  2205. ** workstation \pardesc{wsid}, but only if the structure exists.}
  2206. */
  2207. {
  2208.   if (ptk_structexists(stid))
  2209.     ppost_struct(wsid, stid, priority);
  2210. }  /* ptk_poststruct */
  2211.  
  2212. /*--------------------------------------------------------------------------*/
  2213.  
  2214. typedef struct prirec 
  2215. {
  2216.   Pint ind;
  2217.   ptkboolean distinct;
  2218.   struct prirec *next;
  2219. } prirec;
  2220.  
  2221. /*--------------------------------------------------------------------------*/
  2222.  
  2223. static void ptk_redistributepriorities(C(Pint) ws, 
  2224.                                        C(Pposted_struct_list *) structlist)
  2225. PreANSI(Pint ws)
  2226. PreANSI(Pposted_struct_list *structlist)
  2227. /*
  2228. ** \parambegin
  2229. ** \param{Pint}{ws}{workstation identifier}{IN}
  2230. ** \param{Pposted\_struct\_list *}{structlist}{array of posted structures to reorder}{IN}
  2231. ** \paramend
  2232. ** \blurb{The priorities in the array are redistributed so that they  
  2233. ** are evenly spaced in the range 0-1 whilst retaining their relative 
  2234. ** ordering. 
  2235. ** For exam<ple, the set of priorities 
  2236. **   [0.1, 0.4, 0.45, 0.475, 0.4875, 0.5, 0.9, 0.95, 1] 
  2237. ** would become 
  2238. **   [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9].}
  2239. */
  2240. {
  2241.   Pint s, pricount;
  2242.   prirec *p, *prilist, *ptr;
  2243.   ptkboolean placefound, founddistinct;
  2244.   Pfloat currpriority, pristep;
  2245.  
  2246.   /* first order priorities into a linked list */
  2247.   prilist = (prirec *)malloc(sizeof(prirec));
  2248.   /* start list off with first priority in array */
  2249.   prilist->ind = 0;
  2250.   prilist->distinct = TRUE;
  2251.   prilist->next = NULL;
  2252.   pricount = 1;
  2253.   for (s = 0; s < structlist->num_postings; s++) 
  2254.   {
  2255.     p = (prirec *)malloc(sizeof(prirec));
  2256.     p->ind = s;
  2257.     /* check against first item in list */
  2258.     if (structlist->postings[s].disp_pri ==
  2259.         structlist->postings[prilist->ind].disp_pri)
  2260.     {
  2261.       /* insert immediately after first entry in list */
  2262.       p->next = prilist->next;
  2263.       p->distinct = FALSE;
  2264.       prilist->next = p;
  2265.     } 
  2266.     else 
  2267.     if (structlist->postings[s].disp_pri < 
  2268.         structlist->postings[prilist->ind].disp_pri) 
  2269.     {
  2270.       /* insert point at start of list */
  2271.       p->next = prilist;
  2272.       p->distinct = TRUE;
  2273.       prilist = p;
  2274.       pricount++;
  2275.     } 
  2276.     else 
  2277.     {
  2278.       /* search down list until place is found */
  2279.       ptr = prilist;
  2280.       placefound = FALSE;
  2281.       while (ptr->next != NULL && !placefound) 
  2282.       {
  2283.     if (structlist->postings[s].disp_pri ==
  2284.             structlist->postings[ptr->next->ind].disp_pri)
  2285.         {
  2286.       placefound = TRUE;
  2287.       /* insert priority 's' just after priority in list
  2288.       ** which is the same and don't increment 'pricount'
  2289.           */
  2290.       ptr = ptr->next;
  2291.       p->distinct = FALSE;
  2292.       continue;
  2293.     }
  2294.     if (structlist->postings[s].disp_pri < 
  2295.             structlist->postings[ptr->next->ind].disp_pri) 
  2296.         {
  2297.       placefound = TRUE;
  2298.       p->distinct = TRUE;
  2299.       pricount++;
  2300.       continue;
  2301.     }
  2302.     ptr = ptr->next;
  2303.     /* skip over repeated priorities in the list */
  2304.     founddistinct = FALSE;
  2305.     while (ptr->next != NULL && !founddistinct) 
  2306.         {
  2307.       if (ptr->next->distinct)
  2308.         founddistinct = TRUE;
  2309.       else
  2310.         ptr = ptr->next;
  2311.     }
  2312.       }
  2313.       if (!placefound) 
  2314.       {
  2315.     p->distinct = TRUE;
  2316.     pricount++;
  2317.       }
  2318.       /* insert priority at current place in list */
  2319.       p->next = ptr->next;
  2320.       ptr->next = p;
  2321.     }
  2322.   }  /* for */
  2323.   /* 'pricount' now indicates how many distinct priorities there are,
  2324.   ** if there are n distinct priorities then divide the range [0,1] into n+1
  2325.   ** equal parts so that don't have to use priorities 0 and 1.
  2326.   */
  2327.   pristep = 1.0 / (pricount + 1);
  2328.   ptr = prilist;
  2329.   currpriority = 0.0;
  2330.   while (ptr != NULL) 
  2331.   {
  2332.     if (ptr->distinct)   /* increase current priority by one step */
  2333.       currpriority += pristep;
  2334.     structlist->postings[ptr->ind].disp_pri = currpriority;
  2335.     punpost_struct(ws, structlist->postings[ptr->ind].id);
  2336.     ppost_struct(ws, structlist->postings[ptr->ind].id, currpriority);
  2337.     p = ptr;
  2338.     ptr = ptr->next;
  2339.     free(p);
  2340.   }
  2341. }  /* ptk_redistributepriorities */
  2342.  
  2343. /*--------------------------------------------------------------------------*/
  2344.  
  2345. static void ptk_findpriority(C(Pint) ws, C(Prel_pri) relpriority, 
  2346.                              C(Pint) relstruct, C(Pfloat *) priority, 
  2347.                              C(Pint *) error)
  2348. PreANSI(Pint ws)
  2349. PreANSI(Prel_pri relpriority)
  2350. PreANSI(Pint relstruct)
  2351. PreANSI(Pfloat *priority)
  2352. PreANSI(Pint *error)
  2353. /*
  2354. ** \parambegin
  2355. ** \param{}{ws}{workstation identifier}{IN}
  2356. ** \param{}{relpriority}{priority of posted structure relative to ref structure}{IN}
  2357. ** \param{}{relstruct}{reference structure}{IN}
  2358. ** \param{}{priority}{returned priority value}{OUT}
  2359. ** \param{}{error}{error code}{OUT}
  2360. ** \paramend
  2361. ** \blurb{This is an internal procedure called by ptk_postrelative
  2362. ** ptk_changepostpriority, to compute a structure priority given
  2363. ** a reference structure and whether the new priority should be higher
  2364. ** or lower than that of reference structure
  2365. ** WARNING if the new priority requested can not be obtained, because
  2366. ** of one of the following:
  2367. ** 1. asking for a higher priority than 1
  2368. ** 2. asking for lower priority than 0
  2369. ** 3. there is insufficient gap between the priority of 'relstruct' and the
  2370. **    next higher or lower priority to fit in a new priority
  2371. **
  2372. ** all the priorities on the workstation will be redistributed to regular
  2373. ** intervals over the range [0,1].
  2374. ** all the posted structures.}
  2375. */
  2376. {
  2377.   Pint numstructs, s;
  2378.   ptkboolean found, done;
  2379.   Pint relstruct_index, nearest, ind;
  2380.   Pfloat nearest_priority;
  2381.   Pposted_struct_list structlist;
  2382.  
  2383.   if (!ptk_structexists(relstruct)) 
  2384.   {
  2385.     *error = 1;
  2386.     return;
  2387.   }
  2388.   structlist.postings = NULL;
  2389.   pinq_posted_structs(ws, 0, 0, error, &structlist, &numstructs);
  2390.   structlist.postings = (Pposted_struct *)calloc(numstructs, 
  2391.                                               sizeof(Pposted_struct));
  2392.   pinq_posted_structs(ws, numstructs, 0, error, &structlist, &numstructs);
  2393.  
  2394.   /* find position in array of 'relstruct'*/
  2395.   s = 0;
  2396.   found = FALSE;
  2397.   while ((s < numstructs) && (!found)) 
  2398.   {
  2399.     found = (structlist.postings[s].id == relstruct);
  2400.     if (!found)
  2401.       s++;
  2402.   }
  2403.   if (!found) 
  2404.   {
  2405.     return;
  2406.   }
  2407.   *error = 0;
  2408.   relstruct_index = s;
  2409.  
  2410.   /* first check whether requesting higher priority than highest possible
  2411.   ** or lower priority than lowest possible.
  2412.   */
  2413.   if ((relpriority == PPRI_LOWER) && 
  2414.       (structlist.postings[relstruct_index].disp_pri == 0.0) || 
  2415.      ((relpriority == PPRI_HIGHER) &&
  2416.       (structlist.postings[relstruct_index].disp_pri == 1.0))) 
  2417.   {
  2418.     /* redistribute all priorities on workstation to make room
  2419.     ** for a lower or higher priority
  2420.     */
  2421.     ptk_redistributepriorities(ws, &structlist);
  2422.     /* new priority is half way between new priority for 'relstruct'
  2423.     ** and 0 or 1, depending on 'relpriority'.
  2424.     */
  2425.     if (relpriority == PPRI_LOWER)
  2426.       *priority = structlist.postings[relstruct_index].disp_pri / 2.0;
  2427.     else
  2428.       *priority = (structlist.postings[relstruct_index].disp_pri + 1.0) / 2.0;
  2429.     return;
  2430.   }
  2431.  
  2432.   nearest = 0;
  2433.  
  2434.   if (relpriority == PPRI_LOWER) 
  2435.   {
  2436.     nearest_priority = 0.0;
  2437.     for (s = 0; s < numstructs; s++) 
  2438.     {
  2439.       if ((structlist.postings[s].disp_pri < 
  2440.           structlist.postings[relstruct_index].disp_pri) &&
  2441.       (structlist.postings[s].disp_pri > nearest_priority)) 
  2442.       {
  2443.     nearest = s;
  2444.     nearest_priority = structlist.postings[s].disp_pri;
  2445.       }
  2446.     }
  2447.   } 
  2448.   else 
  2449.   {  
  2450.     /* relpriority = PPRI_HIGHER */
  2451.     nearest_priority = 1.0;
  2452.     for (s = 0; s < numstructs; s++) 
  2453.     {
  2454.       if ((structlist.postings[s].disp_pri >
  2455.           structlist.postings[relstruct_index].disp_pri) &&
  2456.       (structlist.postings[s].disp_pri < nearest_priority)) 
  2457.       {
  2458.     nearest = s;
  2459.     nearest_priority = structlist.postings[s].disp_pri;
  2460.       }
  2461.     }
  2462.   }
  2463.  
  2464.   /* new priority will be half way between priority of
  2465.   **  'relstruct' and 'nearest_priority'.
  2466.   */
  2467.  
  2468.   *priority = (structlist.postings[relstruct_index].disp_pri + 
  2469.                nearest_priority) / 2.0;
  2470.  
  2471.   /* if distance between priority of 'relstruct' and
  2472.   ** 'nearest_priority' is so small that new priority computed
  2473.   ** is approx equal to priority of 'relstruct', redistribute
  2474.   ** all priorities on workstation.
  2475.   */
  2476.   if (!ptk_equal(*priority, structlist.postings[relstruct_index].disp_pri))
  2477.     return;
  2478.   ptk_redistributepriorities(ws, &structlist);
  2479.   /* now recompute new priority as before, using new priorities
  2480.   ** for 'relstruct' and 'nearest'. If a priority just higher
  2481.   ** or lower than 'relstruct' was not found (in which case nearest
  2482.   ** is still 0) use 'nearest_priority' rather than priority for
  2483.   ** 'nearest' which will either be 0 or 1.
  2484.   */
  2485.   if (nearest != 0)
  2486.     *priority = (structlist.postings[relstruct_index].disp_pri + 
  2487.                  structlist.postings[nearest].disp_pri) / 2.0;
  2488.   else
  2489.     *priority = (structlist.postings[relstruct_index].disp_pri + 
  2490.                  nearest_priority) / 2.0;
  2491. }  /* ptk_findpriority */
  2492.  
  2493. /*--------------------------------------------------------------------------*/
  2494.  
  2495. /*function:external*/
  2496. extern void ptk_postrelative(C(Pint) ws, C(Pint) structid, 
  2497.                              C(Prel_pri) relpriority, C(Pint) relstruct, 
  2498.                              C(Pint *) error)
  2499. PreANSI(Pint ws)
  2500. PreANSI(Pint structid)
  2501. PreANSI(Prel_pri relpriority)
  2502. PreANSI(Pint relstruct)
  2503. PreANSI(Pint *error)
  2504. /*
  2505. ** \parambegin
  2506. ** \param{Pint}{ws}{workstation identifier}{IN}
  2507. ** \param{Pint}{structid}{structure identifier}{IN}
  2508. ** \param{Prel\_pri}{relpriority}{relative priority}{IN}
  2509. ** \param{Pint}{relstruct}{relative structure identifier}{IN}
  2510. ** \param{Pint *}{error}{error code}{OUT}
  2511. ** \paramend
  2512. ** \blurb{This function posts structure \pardesc{structid} at a priority higher or
  2513. ** lower than that of structure \pardesc{relative structure identifier},
  2514. **  according to \pardesc{relative priority}. 
  2515. **  If \pardesc{relative structure identifier} does not exist, 
  2516. ** \pardesc{error} is set to 
  2517. ** 1. Otherwise, its value is 0.}
  2518. */
  2519. {
  2520.   Pfloat priority;
  2521.  
  2522.   *error = 0;
  2523.   if (!ptk_structexists(structid)) 
  2524.   {
  2525.     printf("ptk_postrelative: %d doesn't exist\n", structid);
  2526.     *error = 1;
  2527.   } 
  2528.   else 
  2529.   {
  2530.     ptk_findpriority(ws, relpriority, relstruct, &priority, error);
  2531.     ppost_struct(ws, structid, priority);
  2532.   }
  2533. }  /* ptk_postrelative */
  2534.  
  2535. /*--------------------------------------------------------------------------*/
  2536.  
  2537. /*function:external*/
  2538. extern void ptk_changepostpriority(C(Pint) ws, C(Pint) structid,
  2539.                            C(Prel_pri) relpriority, C(Pint) relstruct, 
  2540.                            C(Pint *) error)
  2541. PreANSI(Pint ws)
  2542. PreANSI(Pint structid)
  2543. PreANSI(Prel_pri relpriority)
  2544. PreANSI(Pint relstruct)
  2545. PreANSI(Pint *error)
  2546. /*
  2547. ** \parambegin
  2548. ** \param{Pint}{ws}{workstation identifier}{IN}
  2549. ** \param{Pint}{structid}{structure identifier}{IN}
  2550. ** \param{Prel\_pri}{relpriority}{relative priority}{IN}
  2551. ** \param{Pint}{relstruct}{relative structure identifier}{IN}
  2552. ** \param{Pint *}{error}{error code}{OUT}
  2553. ** \paramend
  2554. ** \blurb{This function changes the priority of structure \pardesc{structid}
  2555. **  to immediately higher or lower than that of \pardesc{relstruct},
  2556. ** according to \pardesc{relpriority}. 
  2557. ** If \pardesc{structid} does not exist, 
  2558. ** \pardesc{error} is set to 
  2559. ** 1. Otherwise, its value is 0.}
  2560. */
  2561. {
  2562.   Pfloat priority;
  2563.  
  2564.   *error = 0;
  2565.   if (!ptk_structexists(structid)) 
  2566.   {
  2567.     printf("ptk_changepostpriority: %d doesn't exist\n", structid);
  2568.     *error = 1;
  2569.     return;
  2570.   }
  2571.   ptk_findpriority(ws, relpriority, relstruct, &priority, error);
  2572.   punpost_struct(ws, structid);
  2573.   ppost_struct(ws, structid, priority);
  2574. }  /* ptk_changepostpriority */
  2575.  
  2576. /*--------------------------------------------------------------------------*/
  2577.  
  2578. /*function:external*/
  2579. extern void ptk_inqpostpriority(C(Pint) wsid, C(Pint) structid,
  2580.                                 C(Pfloat *) priority, C(Pint *) err)
  2581. PreANSI(Pint wsid)
  2582. PreANSI(Pint structid)
  2583. PreANSI(Pfloat *priority)
  2584. PreANSI(Pint *err)
  2585. /*
  2586. ** \parambegin
  2587. ** \param{Pint}{wsid}{workstation identifier}{IN}
  2588. ** \param{Pint}{structid}{structure identifier}{IN}
  2589. ** \param{Pfloat *}{priority}{priority value}{IN}
  2590. ** \param{Pint *}{err}{error indicator}{OUT}
  2591. ** \paramend
  2592. ** \blurb{This function may be used to obtain 
  2593. ** the priority of posted structure \pardesc{structid}.
  2594. ** If \pardesc{structid} does not exist, 
  2595. ** \pardesc{err} is set to 
  2596. ** 1. If it is not posted to {\tt wsid} then {\tt err} is set to 2.}
  2597. */
  2598. {
  2599.   Pint numstructs, i;
  2600.   ptkboolean found;
  2601.   Pposted_struct_list structlist;
  2602.  
  2603.   *err = 0;
  2604.   if (!ptk_structexists(structid)) 
  2605.   {
  2606.     *err = 1;
  2607.     fprintf(stderr, "ptk_inqpostpriority: %d doesn't exist\n", structid);
  2608.     return;
  2609.   }
  2610.   structlist.postings = NULL;
  2611.   pinq_posted_structs(wsid, 0, 0, err, &structlist, &numstructs);
  2612.   structlist.postings = (Pposted_struct *)calloc(numstructs, 
  2613.                                               sizeof(Pposted_struct));
  2614.   pinq_posted_structs(wsid, numstructs, 0, err, &structlist, &numstructs);
  2615.   i = 0;
  2616.   found = FALSE;
  2617.   while ((i < numstructs) && (!found)) 
  2618.   {
  2619.     found = (structlist.postings[i].id == structid);
  2620.     if (found)
  2621.       *priority = structlist.postings[i].disp_pri;
  2622.     else
  2623.       i++;
  2624.   }
  2625.   free(structlist.postings);
  2626.   if (!found)
  2627.     *err = 2;
  2628. }  /* ptk_inqpostpriority */
  2629.  
  2630. /*--------------------------------------------------------------------------*/
  2631. /*----------------------- Workstation Functions ----------------------------*/
  2632.  
  2633. /*function:external*/
  2634. extern void ptk_redrawallstructs(C(Pint) wsid, C(Pctrl_flag) flag)
  2635. PreANSI(Pint wsid)
  2636. PreANSI(Pctrl_flag flag)
  2637. /*
  2638. ** \parambegin
  2639. ** \param{Pint}{wsid}{workstation identifier}{IN}
  2640. ** \param{Pctrl\_flag}{flag}{control flag}{IN}
  2641. ** \paramend
  2642. ** \blurb{This function calls REDRAW ALL STRUCTURES only if the
  2643. ** visual state of the workstation is deferred.}
  2644. */
  2645. {
  2646.   Pint err;
  2647.   Pdefer_mode defmode;
  2648.   Pmod_mode modmode;
  2649.   Pdisp_surf_empty disp;
  2650.   Pvisual_st vis;
  2651.  
  2652.   pinq_disp_upd_st(wsid, &err, &defmode, &modmode, &disp, &vis);
  2653.   if (vis == PVISUAL_ST_DEFER)
  2654.     predraw_all_structs(wsid, flag);
  2655. }  /* ptk_redrawallstructs */
  2656.  
  2657. /*--------------------------------------------------------------------------*/
  2658.  
  2659. /*function:external*/
  2660. extern void ptk_copycolourtable(C(Pint) sourcewsid, C(Pint) destwsid)
  2661. PreANSI(Pint sourcewsid)
  2662. PreANSI(Pint destwsid)
  2663. /*
  2664. ** \parambegin
  2665. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  2666. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  2667. ** \paramend
  2668. ** \blurb{This function copies the colour
  2669. **  table from workstation \pardesc{sourcewsid} to
  2670. **  workstation \pardesc{destwsid}.}
  2671. */
  2672. {
  2673.   Pint_list colourind;
  2674.   Pint totlen, err, i, tablesize, wstype;
  2675.   Pcolr_rep rep;
  2676.   Pws_st_tables lengths;
  2677.   Pstore store;
  2678.   void *connid;
  2679.  
  2680.   pcreate_store(&err, &store);
  2681.   pinq_ws_conn_type(destwsid, store, &err, &connid, &wstype);
  2682.  
  2683.   /* Implementation dependent code - colour table size can be
  2684.   ** specified in open workstation in SUN.
  2685.   */
  2686. #ifndef SUN
  2687.   pinq_ws_st_table(wstype, &err, &lengths);
  2688.   tablesize = lengths.colr_reps;
  2689. #endif
  2690. #ifdef SUN
  2691.   tablesize = (Pint)phigs_ws_type_get(wstype, PHIGS_COLOUR_TABLE_SIZE);
  2692. #endif
  2693.  
  2694.   pinq_list_colr_inds(sourcewsid, 0, 0, &err, &colourind, &totlen);
  2695.   colourind.ints = (Pint *)calloc(totlen, sizeof(Pint));
  2696.   colourind.num_ints = totlen;
  2697.   pinq_list_colr_inds(sourcewsid, totlen, 0, &err, &colourind, &totlen);
  2698.   tablesize = PTKMIN(colourind.num_ints, tablesize);
  2699.   for (i = 0; i < tablesize; i++)
  2700.   {
  2701.     pinq_colr_rep(sourcewsid, colourind.ints[i], PINQ_SET, &err, &rep);
  2702.     pset_colr_rep(destwsid, colourind.ints[i], &rep);
  2703.   }
  2704.   ptk_delstore(store);
  2705.   free(colourind.ints);
  2706. }  /* ptk_copycolourtable */
  2707.  
  2708. /*--------------------------------------------------------------------------*/
  2709.  
  2710. /*function:external*/
  2711. extern void ptk_copylinetable(C(Pint) sourcewsid, C(Pint) destwsid)
  2712. PreANSI(Pint sourcewsid)
  2713. PreANSI(Pint destwsid)
  2714. /*
  2715. ** \parambegin
  2716. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  2717. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  2718. ** \paramend
  2719. ** \blurb{This function copies the polyline bundle
  2720. **  table from workstation \pardesc{sourcewsid} to
  2721. **  workstation \pardesc{destwsid}.}
  2722. */
  2723. {
  2724.   Pint_list lineind;
  2725.   Pint totlen, err, i, tablesize, wstype;
  2726.   Pline_bundle rep;
  2727.   Pws_st_tables lengths;
  2728.   Pstore store;
  2729.   void *connid;
  2730.  
  2731.   pcreate_store(&err, &store);
  2732.   pinq_ws_conn_type(destwsid, store, &err, &connid, &wstype);
  2733.   pinq_ws_st_table(wstype, &err, &lengths);
  2734.   pinq_list_line_inds(sourcewsid, 0, 0, &err, &lineind, &totlen);
  2735.   lineind.ints = (Pint *)calloc(totlen, sizeof(Pint));
  2736.   lineind.num_ints = totlen;
  2737.   pinq_list_line_inds(sourcewsid, totlen, 0, &err, &lineind, &totlen);
  2738.   tablesize = PTKMIN(lengths.line_bundles, lineind.num_ints);
  2739.   for (i = 0; i < tablesize; i++)
  2740.   {
  2741.     pinq_line_rep(sourcewsid, lineind.ints[i], PINQ_SET, &err, &rep);
  2742.     pset_line_rep(destwsid, lineind.ints[i], &rep);
  2743.   }
  2744.   ptk_delstore(store);
  2745.   free(lineind.ints);
  2746. }  /* ptk_copylinetable */
  2747.  
  2748. /*--------------------------------------------------------------------------*/
  2749.  
  2750. /*function:external*/
  2751. extern void ptk_copymarkertable(C(Pint) sourcewsid, C(Pint) destwsid)
  2752. PreANSI(Pint sourcewsid)
  2753. PreANSI(Pint destwsid)
  2754. /*
  2755. ** \parambegin
  2756. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  2757. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  2758. ** \paramend
  2759. ** \blurb{This function copies the polymarker bundle
  2760. **  table from workstation \pardesc{sourcewsid} to
  2761. **  workstation \pardesc{destwsid}.}
  2762. */
  2763. {
  2764.   Pint_list markerind;
  2765.   Pint totlen, err, i, tablesize, wstype;
  2766.   Pmarker_bundle rep;
  2767.   Pws_st_tables lengths;
  2768.   Pstore store;
  2769.   void *connid;
  2770.  
  2771.   pcreate_store(&err, &store);
  2772.   pinq_ws_conn_type(destwsid, store, &err, &connid, &wstype);
  2773.   pinq_ws_st_table(wstype, &err, &lengths);
  2774.   pinq_list_marker_inds(sourcewsid, 0, 0, &err, &markerind, &totlen);
  2775.   markerind.ints = (Pint *)calloc(totlen, sizeof(Pint));
  2776.   markerind.num_ints = totlen;
  2777.   pinq_list_marker_inds(sourcewsid, totlen, 0, &err, &markerind, &totlen);
  2778.   tablesize = PTKMIN(lengths.mark_bundles, markerind.num_ints);
  2779.   for (i = 0; i < tablesize; i++)
  2780.   {
  2781.     pinq_marker_rep(sourcewsid, markerind.ints[i], PINQ_SET, &err, &rep);
  2782.     pset_marker_rep(destwsid, markerind.ints[i], &rep);
  2783.   }
  2784.   ptk_delstore(store);
  2785.   free(markerind.ints);
  2786. }  /* ptk_copymarkertable */
  2787.  
  2788. /*--------------------------------------------------------------------------*/
  2789.  
  2790. /*function:external*/
  2791. extern void ptk_copytexttable(C(Pint) sourcewsid, C(Pint) destwsid)
  2792. PreANSI(Pint sourcewsid)
  2793. PreANSI(Pint destwsid)
  2794. /*
  2795. ** \parambegin
  2796. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  2797. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  2798. ** \paramend
  2799. ** \blurb{This function copies the text bundle
  2800. **  table from workstation \pardesc{sourcewsid} to
  2801. **  workstation \pardesc{destwsid}.}
  2802. */
  2803. {
  2804.   Pint_list textind;
  2805.   Pint totlen, err, i, tablesize, wstype;
  2806.   Ptext_bundle rep;
  2807.   Pws_st_tables lengths;
  2808.   Pstore store;
  2809.   void *connid;
  2810.  
  2811.   pcreate_store(&err, &store);
  2812.   pinq_ws_conn_type(destwsid, store, &err, &connid, &wstype);
  2813.   pinq_ws_st_table(wstype, &err, &lengths);
  2814.   pinq_list_text_inds(sourcewsid, 0, 0, &err, &textind, &totlen);
  2815.   textind.ints = (Pint *)calloc(totlen, sizeof(Pint));
  2816.   textind.num_ints = totlen;
  2817.   pinq_list_text_inds(sourcewsid, totlen, 0, &err, &textind, &totlen);
  2818.   tablesize = PTKMIN(lengths.text_bundles, textind.num_ints);
  2819.   for (i = 0; i < tablesize; i++)
  2820.   {
  2821.     pinq_text_rep(sourcewsid, textind.ints[i], PINQ_SET, &err, &rep);
  2822.     pset_text_rep(destwsid, textind.ints[i], &rep);
  2823.   }
  2824.   ptk_delstore(store);
  2825.   free(textind.ints);
  2826. }  /* ptk_copytexttable */
  2827.  
  2828. /*--------------------------------------------------------------------------*/
  2829.  
  2830. /*function:external*/
  2831. extern void ptk_copyinttable(C(Pint) sourcewsid, C(Pint) destwsid)
  2832. PreANSI(Pint sourcewsid)
  2833. PreANSI(Pint destwsid)
  2834. /*
  2835. ** \parambegin
  2836. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  2837. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  2838. ** \paramend
  2839. ** \blurb{This function copies the interior bundle
  2840. **  table from workstation \pardesc{sourcewsid} to
  2841. **  workstation \pardesc{destwsid}.}
  2842. */
  2843. {
  2844.   Pint_list intind;
  2845.   Pint totlen, err, i, tablesize, wstype;
  2846.   Pint_bundle rep;
  2847.   Pws_st_tables lengths;
  2848.   Pstore store;
  2849.   void *connid;
  2850.  
  2851.   pcreate_store(&err, &store);
  2852.   pinq_ws_conn_type(destwsid, store, &err, &connid, &wstype);
  2853.   pinq_ws_st_table(wstype, &err, &lengths);
  2854.   pinq_list_int_inds(sourcewsid, 0, 0, &err, &intind, &totlen);
  2855.   intind.ints = (Pint *)calloc(totlen, sizeof(Pint));
  2856.   intind.num_ints = totlen;
  2857.   pinq_list_int_inds(sourcewsid, totlen, 0, &err, &intind, &totlen);
  2858.   tablesize = PTKMIN(lengths.int_bundles, intind.num_ints);
  2859.   for (i = 0; i < tablesize; i++)
  2860.   {
  2861.     pinq_int_rep(sourcewsid, intind.ints[i], PINQ_SET, &err, &rep);
  2862.     pset_int_rep(destwsid, intind.ints[i], &rep);
  2863.   }
  2864.   ptk_delstore(store);
  2865.   free(intind.ints);
  2866. }  /* ptk_copyinttable */
  2867.  
  2868. /*--------------------------------------------------------------------------*/
  2869.  
  2870. /*function:external*/
  2871. extern void ptk_copyedgetable(C(Pint) sourcewsid, C(Pint) destwsid)
  2872. PreANSI(Pint sourcewsid)
  2873. PreANSI(Pint destwsid)
  2874. /*
  2875. ** \parambegin
  2876. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  2877. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  2878. ** \paramend
  2879. ** \blurb{This function copies the edge bundle
  2880. **  table from workstation \pardesc{sourcewsid} to
  2881. **  workstation \pardesc{destwsid}.}
  2882. */
  2883. {
  2884.   Pint_list edgeind;
  2885.   Pint totlen, err, i, tablesize, wstype;
  2886.   Pedge_bundle rep;
  2887.   Pws_st_tables lengths;
  2888.   Pstore store;
  2889.   void *connid;
  2890.  
  2891.   pcreate_store(&err, &store);
  2892.   pinq_ws_conn_type(destwsid, store, &err, &connid, &wstype);
  2893.   pinq_ws_st_table(wstype, &err, &lengths);
  2894.   pinq_list_edge_inds(sourcewsid, 0, 0, &err, &edgeind, &totlen);
  2895.   edgeind.ints = (Pint *)calloc(totlen, sizeof(Pint));
  2896.   edgeind.num_ints = totlen;
  2897.   pinq_list_edge_inds(sourcewsid, totlen, 0, &err, &edgeind, &totlen);
  2898.   tablesize = PTKMIN(lengths.edge_bundles, edgeind.num_ints);
  2899.   for (i = 0; i < tablesize; i++)
  2900.   {
  2901.     pinq_edge_rep(sourcewsid, edgeind.ints[i], PINQ_SET, &err, &rep);
  2902.     pset_edge_rep(destwsid, edgeind.ints[i], &rep);
  2903.   }
  2904.   ptk_delstore(store);
  2905.   free(edgeind.ints);
  2906. }  /* ptk_copyedgetable */
  2907.  
  2908. /*--------------------------------------------------------------------------*/
  2909.  
  2910. /*function:external*/
  2911. extern void ptk_copyviewtable(C(Pint) sourcewsid, C(Pint) destwsid)
  2912. PreANSI(Pint sourcewsid)
  2913. PreANSI(Pint destwsid)
  2914. /*
  2915. ** \parambegin
  2916. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  2917. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  2918. ** \paramend
  2919. ** \blurb{This function copies the view
  2920. **  table from workstation \pardesc{sourcewsid} to
  2921. **  workstation \pardesc{destwsid}.}
  2922. */
  2923. {
  2924.   Pint_list viewind;
  2925.   Pint totlen, err, i, tablesize, wstype;
  2926.   Pview_rep3 rep, currep;
  2927.   Pws_st_tables lengths;
  2928.   Pstore store;
  2929.   void *connid;
  2930.   Pupd_st updst;
  2931.  
  2932.   pcreate_store(&err, &store);
  2933.   pinq_ws_conn_type(destwsid, store, &err, &connid, &wstype);
  2934.   pinq_ws_st_table(wstype, &err, &lengths);
  2935.   pinq_list_view_inds(sourcewsid, 0, 0, &err, &viewind, &totlen);
  2936.   viewind.ints = (Pint *)calloc(totlen, sizeof(Pint));
  2937.   viewind.num_ints = totlen;
  2938.   pinq_list_view_inds(sourcewsid, totlen, 0, &err, &viewind, &totlen);
  2939.   tablesize = PTKMIN(lengths.view_reps, viewind.num_ints);
  2940.   for (i = 1; i < tablesize; i++)
  2941.   {
  2942.     pinq_view_rep(sourcewsid, viewind.ints[i], &err, &updst, &currep, &rep);
  2943.     pset_view_rep3(destwsid, viewind.ints[i], &rep);
  2944.   }
  2945.   ptk_delstore(store);
  2946.   free(viewind.ints);
  2947. }  /* ptk_copyviewtable */
  2948.  
  2949. /*--------------------------------------------------------------------------*/
  2950.  
  2951. /*function:external*/
  2952. extern void ptk_copypattable(C(Pint) sourcewsid, C(Pint) destwsid)
  2953. PreANSI(Pint sourcewsid)
  2954. PreANSI(Pint destwsid)
  2955. /*
  2956. ** \parambegin
  2957. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  2958. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  2959. ** \paramend
  2960. ** \blurb{This function copies the pattern bundle
  2961. **  table from workstation \pardesc{sourcewsid} to
  2962. **  workstation \pardesc{destwsid}.}
  2963. */
  2964. {
  2965.   Pint_list patind;
  2966.   Pint totlen, err, i, tablesize, wstype;
  2967.   Ppat_rep *rep;
  2968.   Pws_st_tables lengths;
  2969.   Pstore store, patstore;
  2970.   void *connid;
  2971.  
  2972. #ifndef HP
  2973.   pcreate_store(&err, &store);
  2974.   pinq_ws_conn_type(destwsid, store, &err, &connid, &wstype);
  2975.   pinq_ws_st_table(wstype, &err, &lengths);
  2976.   pinq_list_pat_inds(sourcewsid, 0, 0, &err, &patind, &totlen);
  2977.   patind.ints = (Pint *)calloc(totlen, sizeof(Pint));
  2978.   patind.num_ints = totlen;
  2979.   pinq_list_pat_inds(sourcewsid, totlen, 0, &err, &patind, &totlen);
  2980.   tablesize = PTKMIN(lengths.pat_reps, patind.num_ints);
  2981.   for (i = 0; i < tablesize; i++)
  2982.   {
  2983.     pcreate_store(&err, &patstore);
  2984.     pinq_pat_rep(sourcewsid, patind.ints[i], PINQ_SET, patstore, &err, &rep);
  2985.     pset_pat_rep(destwsid, patind.ints[i], rep);
  2986.     ptk_delstore(patstore);
  2987.   }
  2988.   ptk_delstore(store);
  2989.   free(patind.ints);
  2990. #endif
  2991. }  /* ptk_copypattable */
  2992.  
  2993. /*--------------------------------------------------------------------------*/
  2994.  
  2995. /*function:external*/
  2996. extern void ptk_copywssttable(C(Pint) sourcewsid, C(Pint) destwsid)
  2997. PreANSI(Pint sourcewsid)
  2998. PreANSI(Pint destwsid)
  2999. /*
  3000. ** \parambegin
  3001. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  3002. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  3003. ** \paramend
  3004. ** \blurb{This function copies the workstation colour,
  3005. ** polyline bundle, polymarker bundle, interior bundle, edge bundle,
  3006. ** text bundle, pattern bundle and view
  3007. **  tables from workstation \pardesc{sourcewsid} to
  3008. **  workstation \pardesc{destwsid}.}
  3009. */
  3010. {
  3011.   /* colour table */
  3012.   ptk_copycolourtable(sourcewsid, destwsid);
  3013.   /* polyline table */
  3014.   ptk_copylinetable(sourcewsid, destwsid);
  3015.   /* polymarker table */
  3016.   ptk_copymarkertable(sourcewsid, destwsid);
  3017.   /* interior table */
  3018.   ptk_copyinttable(sourcewsid, destwsid);
  3019.   /* edge table */
  3020.   ptk_copyedgetable(sourcewsid, destwsid);
  3021.   /* text table */
  3022.   ptk_copytexttable(sourcewsid, destwsid);
  3023.   /* pattern table */
  3024.   ptk_copypattable(sourcewsid, destwsid);
  3025.   /* view table */
  3026.   ptk_copyviewtable(sourcewsid, destwsid);  
  3027. }  /* ptk_copywssttable */
  3028.  
  3029. /*--------------------------------------------------------------------------*/
  3030.  
  3031. /*function:external*/
  3032. extern void ptk_copypostedstruct(C(Pint) sourcewsid, C(Pint) destwsid)
  3033. PreANSI(Pint sourcewsid)
  3034. PreANSI(Pint destwsid)
  3035. /*
  3036. ** \parambegin
  3037. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  3038. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  3039. ** \paramend
  3040. ** \blurb{This function posts all the structures already posted to
  3041. ** workstation \pardesc{sourcewsid} to  workstation  \pardesc{destwsid}.}
  3042. */
  3043. {
  3044.   Pint err, totlen, i;
  3045.   Pposted_struct_list postlist;
  3046.  
  3047.   pinq_posted_structs(sourcewsid, 0, 0, &err, &postlist, &totlen);
  3048.   postlist.postings = (Pposted_struct *)calloc(totlen, 
  3049.                                                sizeof(Pposted_struct));
  3050.   postlist.num_postings = totlen;
  3051.   pinq_posted_structs(sourcewsid, totlen, 0, &err, &postlist, &totlen);
  3052.   for (i = 0; i < postlist.num_postings; i++)
  3053.     ppost_struct(destwsid, postlist.postings[i].id, 
  3054.                  postlist.postings[i].disp_pri);
  3055.   free(postlist.postings);
  3056. }  /* ptk_copypostedstruct */
  3057.  
  3058. /*--------------------------------------------------------------------------*/
  3059.  
  3060. /*function:external*/
  3061. extern void ptk_copyhilightfilter(C(Pint) sourcewsid, C(Pint) destwsid)
  3062. PreANSI(Pint sourcewsid)
  3063. PreANSI(Pint destwsid)
  3064. /*
  3065. ** \parambegin
  3066. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  3067. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  3068. ** \paramend
  3069. ** \blurb{This function copies the highlighting filter 
  3070. ** from workstation \pardesc{sourcewsid} to workstation \pardesc{destwsid}.}
  3071. */
  3072. {
  3073.   Pint err;
  3074.   Pstore store;
  3075.   Pfilter *highfilt;
  3076.  
  3077.   /* highlight filter */
  3078.   pcreate_store(&err, &store);
  3079.   pinq_highl_filter(sourcewsid, store, &err, &highfilt);
  3080.   pset_highl_filter(destwsid, highfilt);
  3081.   ptk_delstore(store);
  3082. }  /* ptk_copyhilightfilter */
  3083.  
  3084. /*--------------------------------------------------------------------------*/
  3085.  
  3086. /*function:external*/
  3087. extern void ptk_copyinvisfilter(C(Pint) sourcewsid, C(Pint) destwsid)
  3088. PreANSI(Pint sourcewsid)
  3089. PreANSI(Pint destwsid)
  3090. /*
  3091. ** \parambegin
  3092. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  3093. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  3094. ** \paramend
  3095. ** \blurb{This function copies the invisibilty filter 
  3096. ** from workstation \pardesc{sourcewsid} to workstation \pardesc{destwsid}.}
  3097. */
  3098. {
  3099.   Pint err;
  3100.   Pstore store;
  3101.   Pfilter *invisfilt;
  3102.  
  3103.   /* invisibility filter */
  3104.   pcreate_store(&err, &store);
  3105.   pinq_invis_filter(sourcewsid, store, &err, &invisfilt);
  3106.   pset_invis_filter(destwsid, invisfilt);
  3107.   ptk_delstore(store);
  3108. }  /* ptk_copyinvisfilter */
  3109.  
  3110. /*--------------------------------------------------------------------------*/
  3111.  
  3112. /*function:external*/
  3113. extern void ptk_copyhlhsrmode(C(Pint) sourcewsid, C(Pint) destwsid)
  3114. PreANSI(Pint sourcewsid)
  3115. PreANSI(Pint destwsid)
  3116. /*
  3117. ** \parambegin
  3118. ** \param{Pint}{sourcewsid}{source workstation identifier}{IN}
  3119. ** \param{Pint}{destwsid}{destination workstation identifier}{IN}
  3120. ** \paramend
  3121. ** \blurb{This function copies the HLHSR mode
  3122. ** from workstation \pardesc{sourcewsid} to workstation \pardesc{destwsid}.}
  3123. */
  3124. {
  3125.   /* inquire hlhsr mode */
  3126.   /* inquire wstype */
  3127.   /* inquire hlhsr facilities */
  3128.   /* if mode available set otherwise default */
  3129. }  /* ptk_copyhlhsrmode */
  3130.  
  3131. /* copy workstation window, workstation viewport, deferral mode,
  3132. ** modification mode, colour model, input devices.
  3133. */
  3134.  
  3135. /*--------------------------------------------------------------------------*/
  3136. /*------------------------ Inquiry Functions -------------------------------*/
  3137.  
  3138. /*function:external*/
  3139. extern void ptk_inqmaxdevicecoords(C(Pint) wsid, C(Pfloat *) maxdevx, 
  3140.                                    C(Pfloat *) maxdevy)
  3141. PreANSI(Pint wsid)
  3142. PreANSI(Pfloat *maxdevx)
  3143. PreANSI(Pfloat *maxdevy)
  3144. /*
  3145. ** \parambegin
  3146. ** \param{Pint}{wsid}{workstation identifier}{IN}
  3147. ** \param{Pfloat *}{maxdevx}{maximum device coords along x axis}{OUT}
  3148. ** \param{Pfloat *}{maxdevy}{maximum device coords along y axis}{OUT}
  3149. ** \paramend
  3150. ** \blurb{This function returns the the 
  3151. ** maximum device coordinates for $x$ and $y$ for workstation \pardesc{wsid}.}
  3152. */
  3153. {   
  3154.   Pint err, wstype;
  3155.   Pdisp_space_size disprec;
  3156.   Pstore store;
  3157.   void *connid;
  3158.  
  3159.   pcreate_store(&err, &store);
  3160.   pinq_ws_conn_type(wsid, store, &err, &connid, &wstype);
  3161.   pinq_disp_space_size(wstype, &err, &disprec);
  3162.   *maxdevx = disprec.size_dc.size_x;
  3163.   *maxdevy = disprec.size_dc.size_y;
  3164.   ptk_delstore(store);
  3165. }  /* ptk_inqmaxdevicecoords */
  3166.  
  3167. /*--------------------------------------------------------------------------*/
  3168.  
  3169. /*function:external*/
  3170. extern void ptk_inqmaxdevicecoords3(C(Pint) wsid, C(Pfloat *) maxdevx, 
  3171.                                     C(Pfloat *) maxdevy, C(Pfloat *) maxdevz)
  3172. PreANSI(Pint wsid)
  3173. PreANSI(Pfloat *maxdevx)
  3174. PreANSI(Pfloat *maxdevy)
  3175. PreANSI(Pfloat *maxdevz)
  3176. /*
  3177. ** \parambegin
  3178. ** \param{Pint}{wsid}{workstation identifier}{IN}
  3179. ** \param{Pfloat *}{maxdevx}{maximum device coords along x axis}{OUT}
  3180. ** \param{Pfloat *}{maxdevy}{maximum device coords along y axis}{OUT}
  3181. ** \param{Pfloat *}{maxdevz}{maximum device coords along z axis}{OUT}
  3182. ** \paramend
  3183. ** \blurb{This function returns the the 
  3184. ** maximum device coordinates for $x$, $y$
  3185. ** and $z$ for workstation \pardesc{wsid}.}
  3186. */
  3187. {   
  3188.   Pint err, totsize;
  3189.   Pint wstype;
  3190.   Pdisp_space_size3 disprec;
  3191.   Pstore store;
  3192.   void *connid;
  3193.  
  3194.   pcreate_store(&err, &store);
  3195.   pinq_ws_conn_type(wsid, store, &err, &connid, &wstype);
  3196.   pinq_disp_space_size3(wstype, &err, &disprec);
  3197.   *maxdevx = disprec.size_dc.size_x;
  3198.   *maxdevy = disprec.size_dc.size_y;
  3199.   *maxdevz = disprec.size_dc.size_z;
  3200.   ptk_delstore(store);
  3201. }  /* ptk_inqmaxdevicecoords3 */
  3202.  
  3203. /*--------------------------------------------------------------------------*/
  3204. /*---------------------- Miscellaneous Functions ---------------------------*/
  3205.  
  3206. static void box(C(Ppoint *) pos, C(Pint) c, C(Ppoint *) size)
  3207. PreANSI(Ppoint *pos)
  3208. PreANSI(Pint c)
  3209. PreANSI(Ppoint *size)
  3210. /*
  3211. ** \parambegin
  3212. ** \param{}{xx}{position of box on x axis}{IN}
  3213. ** \param{}{yy}{position of box on y axis}{IN}
  3214. ** \param{}{c}{interior colour of box (index to colour table)}{IN}
  3215. ** \param{}{boxptr}{pointer to ptkscolourtable struct}{IN}
  3216. ** \paramend
  3217. ** \blurb{Draws a box and fills with given colour.}
  3218. */
  3219. {
  3220.   Ppoint boxcoords[4];
  3221.   Ppoint textpoint;
  3222.   char textnum[5];
  3223.   Ppoint_list boxpts;
  3224.  
  3225.   textpoint.x = pos->x + size->x / 2.0;
  3226.   textpoint.y = pos->y + size->y / 2.0;
  3227.  
  3228.   boxcoords[0] = ptk_point(pos->x, pos->y);
  3229.   boxcoords[1] = ptk_point(pos->x + size->x, pos->y);
  3230.   boxcoords[2] = ptk_point(pos->x + size->x, pos->y + size->y);
  3231.   boxcoords[3] = ptk_point(pos->x, pos->y + size->y);
  3232.  
  3233.   sprintf(textnum, "%d", c);
  3234.   if (c >= 0)
  3235.   {
  3236.     pset_int_colr_ind(c);
  3237.     boxpts.num_points = 4;
  3238.     boxpts.points = boxcoords;
  3239.     pfill_area(&boxpts);
  3240.     ptext(&textpoint, textnum);
  3241.   }
  3242. }  /* box */
  3243.  
  3244. /*--------------------------------------------------------------------------*/
  3245.  
  3246. /*function:external*/
  3247. extern void ptk_drawcolourtable(C(Pint) stid, C(Pint) llim, C(Pint) ulim)
  3248. PreANSI(Pint stid)
  3249. PreANSI(Pint llim)
  3250. PreANSI(Pint ulim)
  3251. /*
  3252. ** \parambegin
  3253. ** \param{Pint}{stid}{structure identifier}{IN}
  3254. ** \param{Pint}{llim}{lower index value of colour table range}{IN}
  3255. ** \param{Pint}{ulim}{upper limit of colour table range.}{IN}
  3256. ** \paramend
  3257. ** \blurb{This function draws a rectangular array of boxes representing
  3258. ** the range \pardesc{llim} to \pardesc{ulim} of
  3259. ** the workstation colour table. The boxes are drawn into structure
  3260. ** \pardesc{stid}.}
  3261. */
  3262.   Pint x, y, numboxes, cindex;
  3263.   Ptext_align alignrec;
  3264.   Pfloat entryrange;
  3265.   Ppoint size, pos;
  3266.  
  3267.   entryrange = (Pfloat)(ulim - llim + 1);
  3268.   entryrange = sqrt(entryrange);
  3269.   /* numboxes = number of boxes down each side of grid */
  3270.   numboxes = (entryrange/1);
  3271.   if (entryrange > numboxes) { numboxes++; } 
  3272.  
  3273.   size.x = 1.0 / numboxes;
  3274.   size.y = 1.0 / numboxes;
  3275.   alignrec.hor = PHOR_CTR;
  3276.   alignrec.vert = PVERT_HALF;
  3277.  
  3278.   ptk_openstruct(stid);
  3279.   pset_text_align(&alignrec);
  3280.   pset_char_ht(size.y / 4.0);
  3281.   pset_int_style(PSTYLE_SOLID);
  3282.   for (y = 0; y < numboxes; y++) 
  3283.   {
  3284.     for (x = 0; x < numboxes; x++)
  3285.     {
  3286.       pos = ptk_point((Pfloat)x * size.x, 1.0 - ((Pfloat)(y + 1) * size.y));
  3287.       cindex = (y * numboxes) + x + llim;
  3288.       if (cindex > ulim)
  3289.         cindex = -1;
  3290.       box(&pos, cindex, &size);
  3291.     }
  3292.   }
  3293.   ptk_closestruct();
  3294. }  /* ptk_drawcolourtable */
  3295.  
  3296. /*--------------------------------------------------------------------------*/
  3297.  
  3298. /*function:external*/
  3299. extern void ptk_arrow(C(Pfloat) length, C(Pfloat) width, C(Ppoint3 *) centre, 
  3300.                       C(Pfloat) angle)
  3301. PreANSI(Pfloat length)
  3302. PreANSI(Pfloat width)
  3303. PreANSI(Ppoint3 *centre)
  3304. PreANSI(Pfloat angle)
  3305. /*
  3306. ** \parambegin
  3307. ** \param{Pfloat}{length}{length of arrow}{IN}
  3308. ** \param{Pfloat}{width}{width of arrow}{IN}
  3309. ** \param{Ppoint3 *}{centre}{centre of arrow}{IN}
  3310. ** \param{Pfloat}{angle}{rotation of arrow in degrees anti-clockwise about 
  3311. ** arrow pointing along x-axis.}{IN}
  3312. ** \paramend
  3313. ** \blurb{This function draws an arrow with the specified
  3314. ** length \pardesc{length} and \pardesc{width}, rotated through
  3315. **  \pardesc{angle}, centred at \pardesc{centre}.} 
  3316. */
  3317. {
  3318.   Pmatrix3 matrix;
  3319.   Ppoint3 fp[7];
  3320.   Pint i;
  3321.   Ppoint_list3 sets;
  3322.  
  3323.   ptk_rotate3(angle, 3, PTYPE_REPLACE, matrix);
  3324.   ptk_shift3(centre, PTYPE_POSTCONCAT, matrix);
  3325.   fp[0] = ptk_point3(-width/4.0, -length/2.0, 0.0);
  3326.   fp[1] = ptk_point3(fp[0].x, length/6.0, 0.0);
  3327.   fp[2] = ptk_point3(-width/2.0, fp[1].y, 0.0);
  3328.   fp[3] = ptk_point3(0.0, -fp[0].y, 0.0); 
  3329.   fp[4] = ptk_point3(width/2.0, fp[1].y, 0.0); 
  3330.   fp[5] = ptk_point3(-fp[0].x, fp[1].y, 0.0);
  3331.   fp[6] = ptk_point3(fp[5].x, fp[0].y, 0.0);
  3332.   for (i = 0; i < 7; i++)
  3333.     fp[i] = ptk_transform3(matrix, &fp[i]);
  3334.   sets.num_points = 7;
  3335.   sets.points = fp;
  3336.   ptk_fillareaset3(1, &sets); 
  3337. }  /* ptk_arrow */
  3338.  
  3339. /*--------------------------------------------------------------------------*/
  3340.  
  3341. /*function:external*/
  3342. extern void ptk_grid(C(Pint) stid)
  3343. PreANSI(Pint stid)
  3344. /*
  3345. ** \parambegin
  3346. ** \param{Pint}{stid}{grid structure identifier}{IN}
  3347. ** \paramend
  3348. ** \blurb{This functions draws a grid of lines on [0,1],
  3349. **  into structure \pardesc{stid}. }
  3350. */
  3351. {
  3352.   Pint i;
  3353.   Ppoint pts[2], textpt;
  3354.   Ptext_align al;
  3355.   char str[80];
  3356.   Ppoint_list gridpts;
  3357.  
  3358.   gridpts.num_points = 2;
  3359.   gridpts.points = pts;
  3360.   ptk_openstruct(stid);
  3361.   al.hor = PHOR_CTR;
  3362.   al.vert = PVERT_NORM;
  3363.   pset_text_align(&al);
  3364.   pset_char_ht(0.01);
  3365.   for (i = 1; i <= 9; i++) 
  3366.   {   
  3367.     /* horizontal lines, x = 0.1,..,0.9 */
  3368.     pts[0] = ptk_point((Pfloat)i * 0.1, 0.93);
  3369.     pts[1] = ptk_point((Pfloat)i * 0.1, 0.07);
  3370.     ppolyline(&gridpts);
  3371.     sprintf(str, "%d", i);
  3372.     textpt = ptk_point(i * 0.1, 0.94); 
  3373.     ptext(&textpt, str);
  3374.     textpt = ptk_point(i * 0.1, 0.04); 
  3375.     ptext(&textpt, str);
  3376.   }
  3377.  
  3378.   al.hor = PHOR_NORM;
  3379.   al.vert = PVERT_HALF;
  3380.   pset_text_align(&al);
  3381.   for (i = 1; i <= 9; i++) 
  3382.   {   
  3383.     /* vertical lines, y = 0.1,..,0.9 */
  3384.     pts[0] = ptk_point(0.07, i * 0.1);
  3385.     pts[1] = ptk_point(0.93, i * 0.1);
  3386.     ppolyline(&gridpts);
  3387.     sprintf(str, "%d", i);
  3388.     textpt = ptk_point(0.03, i * 0.1); 
  3389.     ptext(&textpt, str);
  3390.     textpt = ptk_point(0.94, i * 0.1); 
  3391.     ptext(&textpt, str);
  3392.   }
  3393.   ptk_closestruct();
  3394. }  /* ptk_grid */
  3395.  
  3396. /*--------------------------------------------------------------------------*/
  3397.  
  3398. /*function:external*/
  3399. extern void ptk_framebox(C(Ppoint3 *) boxcentre, C(Ppoint *) boxsize,
  3400.            C(Ppoint *) framesize, C(Pint) boxcolour, C(Pint) edgecolour,
  3401.            C(Pint) tlcolour, C(Pint) brcolour)
  3402. PreANSI(Ppoint3 *boxcentre)
  3403. PreANSI(Ppoint *boxsize)
  3404. PreANSI(Ppoint *framesize)
  3405. PreANSI(Pint boxcolour)
  3406. PreANSI(Pint edgecolour)
  3407. PreANSI(Pint tlcolour)
  3408. PreANSI(Pint brcolour)
  3409. /*
  3410. ** \parambegin
  3411. ** \param{Ppoint3 *}{boxcentre}{centre of box}{IN}
  3412. ** \param{Ppoint *}{boxsize}{height and width box}{IN}
  3413. ** \param{Ppoint *}{framesize}{height and width of frame}{IN}
  3414. ** \param{Pint}{boxcolour}{box interior colour index}{IN}
  3415. ** \param{Pint}{edgecolour}{box edge colour index}{IN}
  3416. ** \param{Pint}{tlcolour}{frame top-left colour index}{IN}
  3417. ** \param{Pint}{brcolour}{frame bottom-right colour index}{IN}
  3418. ** \paramend
  3419. ** \blurb{This function draws a box in the open
  3420. **  structure with a frame to give a 3D
  3421. ** effect.}
  3422. */
  3423. {
  3424.   Ppoint3 pts[6];
  3425.   Ppoint_list3 sets, areapts;
  3426.   
  3427.   pset_int_style(PSTYLE_SOLID);
  3428.   pts[0] = ptk_point3(boxcentre->x - (boxsize->x / 2.0) - framesize->x, 
  3429.                       boxcentre->y - (boxsize->y / 2.0) - framesize->y,
  3430.                       boxcentre->z);
  3431.   pts[1] = ptk_point3(pts[0].x, pts[0].y + boxsize->y + (2.0 * framesize->y),
  3432.                       boxcentre->z);
  3433.   pts[2] = ptk_point3(pts[0].x + boxsize->x + (2.0 * framesize->x), pts[1].y,
  3434.                       boxcentre->z);
  3435.   pts[3] = ptk_point3(pts[2].x - framesize->x, 
  3436.                       pts[2].y - framesize->y, boxcentre->z);
  3437.   pts[4] = ptk_point3(pts[1].x + framesize->x, pts[3].y, 
  3438.                       boxcentre->z);
  3439.   pts[5] = ptk_point3(pts[4].x, pts[0].y + framesize->y, 
  3440.                       boxcentre->z);
  3441.  
  3442.   pset_int_colr_ind(tlcolour);
  3443.   pts[2] = ptk_point3(pts[0].x + boxsize->x + (2.0 * framesize->x), pts[1].y,
  3444.                       boxcentre->z);
  3445.   areapts.num_points = 6;
  3446.   areapts.points = pts;
  3447.   pset_edge_flag(PEDGE_OFF);
  3448.   pfill_area3(&areapts);
  3449.  
  3450.   pset_int_colr_ind(brcolour);
  3451.   pts[1].x += boxsize->x + (2.0 * framesize->x);
  3452.   pts[1].y -= boxsize->y + (2.0 * framesize->y);
  3453.   pts[4].x = pts[3].x;
  3454.   pts[4].y = pts[5].y;
  3455.   pfill_area3(&areapts);
  3456.  
  3457.   pts[2] = ptk_point3(pts[3].x, pts[5].y, boxcentre->z);
  3458.   pts[4] = ptk_point3(pts[0].x + framesize->x, pts[3].y, 
  3459.                       boxcentre->z);
  3460.   pset_int_colr_ind(boxcolour);
  3461.   pset_edge_flag(PEDGE_ON);
  3462.   pset_edge_colr_ind(edgecolour);
  3463.   sets.num_points = 4;
  3464.   sets.points = &pts[2];
  3465.   ptk_fillareaset3(1, &sets);
  3466. }  /* ptk_framebox */
  3467.  
  3468. /*--------------------------------------------------------------------------*/
  3469.  
  3470. /* phigslib */
  3471.  
  3472. /* End. */
  3473.